diff options
Diffstat (limited to 'src/transform2.ts')
-rw-r--r-- | src/transform2.ts | 52 |
1 files changed, 5 insertions, 47 deletions
diff --git a/src/transform2.ts b/src/transform2.ts index 94cd02fa2..8f67e4523 100644 --- a/src/transform2.ts +++ b/src/transform2.ts @@ -8,9 +8,9 @@ import micromark from 'micromark'; import gfmSyntax from 'micromark-extension-gfm'; import matter from 'gray-matter'; import gfmHtml from 'micromark-extension-gfm/html.js'; -import { walk, parse } from './compiler.js'; +import { walk } from 'estree-walker'; +import { parse } from './compiler/index.js'; import markdownEncode from './markdown-encode.js'; -import { preparse } from './parser.js'; const { transformSync } = esbuild; @@ -153,56 +153,12 @@ function getComponentWrapper(_name: string, { type, url }: { type: string; url: throw new Error('Unknown Component Type: ' + name); } -function runPreparser(template: string): string { - const doc = preparse(template, (tag) => { - if (tag.tagName === 'script') { - let isSetup = false; - for (let attr of tag.attributes) { - if (attr.name === 'hmx' && attr.value === 'setup') { - isSetup = true; - break; - } - } - if (isSetup && typeof tag.children[0] === 'string') { - debugger; - - const content = tag.children[0]; - let { code } = transformSync(content, { - loader: 'tsx', - jsxFactory: 'h', - jsxFragment: 'Fragment', - charset: 'utf8', - }); - return { - ...tag, - children: [ - { - type: 0, - data: code, - start: 0, - end: 0, - }, - ], - }; - } - } - - return tag; - }); - - // TODO codegen - - return template; -} - async function convertHmxToJsx(template: string, compileOptions: CompileOptions) { await eslexer.init; - //template = runPreparser(template); - const ast = parse(template, {}); + const script = ast.instance ? ast.instance.content : ""; // Todo: Validate that `h` and `Fragment` aren't defined in the script - const script = ast.instance ? astring.generate(ast.instance.content) : ''; const [scriptImports] = eslexer.parse(script, 'optional-sourcename'); const components = Object.fromEntries( @@ -221,6 +177,7 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions) let currentDepth = 0; walk(ast.html as any, { + // @ts-ignore enter(node: TemplateNode, parent, prop, index) { // console.log("enter", node.type); switch (node.type) { @@ -329,6 +286,7 @@ async function convertHmxToJsx(template: string, compileOptions: CompileOptions) throw new Error('Unexpected node type: ' + node.type); } }, + // @ts-ignore leave(node: TemplateNode, parent, prop, index) { // console.log("leave", node.type); switch (node.type) { |