summaryrefslogtreecommitdiff
path: root/src/codegen/index.ts
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2021-03-22 00:26:59 -0700
committerGravatar Fred K. Schott <fkschott@gmail.com> 2021-03-22 00:26:59 -0700
commitd125d57b3a314d994149f84c18747c85bdf1f0b1 (patch)
tree378e6b3f0c37b99278fb5eda41e194088d3ac020 /src/codegen/index.ts
parentf28590e640449c849727222bcf4451544c65df36 (diff)
downloadastro-d125d57b3a314d994149f84c18747c85bdf1f0b1.tar.gz
astro-d125d57b3a314d994149f84c18747c85bdf1f0b1.tar.zst
astro-d125d57b3a314d994149f84c18747c85bdf1f0b1.zip
add typescript support for expressions
Diffstat (limited to 'src/codegen/index.ts')
-rw-r--r--src/codegen/index.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/codegen/index.ts b/src/codegen/index.ts
index 4cba263df..725546f51 100644
--- a/src/codegen/index.ts
+++ b/src/codegen/index.ts
@@ -146,8 +146,8 @@ function getComponentWrapper(_name: string, { type, url }: { type: string; url:
throw new Error('Unknown Component Type: ' + name);
}
-function compileScriptSafe(raw: string, loader: 'jsx' | 'tsx'): string {
- let compiledCode = compileExpressionSafe(raw, loader);
+function compileScriptSafe(raw: string): string {
+ let compiledCode = compileExpressionSafe(raw);
// esbuild treeshakes unused imports. In our case these are components, so let's keep them.
const imports = eslexer
.parse(raw)[0]
@@ -161,9 +161,9 @@ function compileScriptSafe(raw: string, loader: 'jsx' | 'tsx'): string {
return compiledCode;
}
-function compileExpressionSafe(raw: string, loader: 'jsx' | 'tsx'): string {
+function compileExpressionSafe(raw: string): string {
let { code } = transformSync(raw, {
- loader,
+ loader: 'tsx',
jsxFactory: 'h',
jsxFragment: 'Fragment',
charset: 'utf8',
@@ -175,7 +175,7 @@ export async function codegen(ast: Ast, { compileOptions }: CodeGenOptions): Pro
await eslexer.init;
// Compile scripts as TypeScript, always
- const script = compileScriptSafe(ast.module ? ast.module.content : '', 'tsx');
+ const script = compileScriptSafe(ast.module ? ast.module.content : '');
// Todo: Validate that `h` and `Fragment` aren't defined in the script
const [scriptImports] = eslexer.parse(script, 'optional-sourcename');
@@ -198,7 +198,7 @@ export async function codegen(ast: Ast, { compileOptions }: CodeGenOptions): Pro
enter(node: TemplateNode) {
switch (node.type) {
case 'MustacheTag':
- let code = compileExpressionSafe(node.expression, 'jsx');
+ let code = compileExpressionSafe(node.expression);
let matches: RegExpExecArray[] = [];
let match: RegExpExecArray | null | undefined;