@sola-air-ui/compiler 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +38 -31
- package/src/index.js +24 -10
package/package.json
CHANGED
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@sola-air-ui/compiler",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Compiler for Sola single-file components (.sola) — transforms template + script + style to ES modules",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./src/index.js",
|
|
7
|
-
"bin": {
|
|
8
|
-
"sola": "./src/cli.js"
|
|
9
|
-
},
|
|
10
|
-
"exports": {
|
|
11
|
-
".": "./src/index.js"
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"test": "node test/compiler.test.js"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@sola-air-ui/compiler",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Compiler for Sola single-file components (.sola) — transforms template + script + style to ES modules",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"sola": "./src/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node test/compiler.test.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"sola",
|
|
18
|
+
"compiler",
|
|
19
|
+
"sfc",
|
|
20
|
+
"single-file-component",
|
|
21
|
+
"zero-vdom",
|
|
22
|
+
"build-tool"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"homepage": "https://sola-air.dev",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/rbm3267/sola-air"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"acorn": "^8.10.0",
|
|
32
|
+
"htmlparser2": "^9.0.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/src/index.js
CHANGED
|
@@ -192,6 +192,7 @@ function stripTypeScript(code) {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
export function compile(source, options = {}) {
|
|
195
|
+
const target = options.target || 'esm'; // 'esm' | 'iife'
|
|
195
196
|
const { script: scriptContent, style: styleContent, template: rawTemplateSource } = extractScriptAndStyle(source);
|
|
196
197
|
const scopeHash = hashString(styleContent || rawTemplateSource);
|
|
197
198
|
const hasStyles = styleContent.trim().length > 0;
|
|
@@ -585,16 +586,27 @@ export function compile(source, options = {}) {
|
|
|
585
586
|
root.children.forEach(child => emitNode(child, '__target'));
|
|
586
587
|
|
|
587
588
|
// Assemble final output module
|
|
589
|
+
const CORE_EXPORTS = 'createSignal, createDerived, createEffect, createIntent, createData, onMount, onDestroy, pushContext, popContext, __flush_mounts, __flush_destroys';
|
|
588
590
|
let output = '';
|
|
589
|
-
output += `// Compiled by @sola-air-ui/compiler v1.0.
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
output += `
|
|
591
|
+
output += `// Compiled by @sola-air-ui/compiler v1.0.3\n`;
|
|
592
|
+
|
|
593
|
+
if (target === 'iife') {
|
|
594
|
+
// ServiceNow / no-bundler mode: pull from window.SolaCore global
|
|
595
|
+
output += `(function() {\n`;
|
|
596
|
+
output += `const { ${CORE_EXPORTS} } = window.SolaCore;\n`;
|
|
597
|
+
for (const imp of componentImports) {
|
|
598
|
+
output += `// Note: sub-component ${imp.localName} must be pre-loaded before this script\n`;
|
|
599
|
+
}
|
|
600
|
+
output += `\n`;
|
|
601
|
+
output += `window['${options.exportName || 'SolaComponent'}'] = function mount(__target, props = {}) {\n`;
|
|
602
|
+
} else {
|
|
603
|
+
output += `import { ${CORE_EXPORTS} } from '@sola-air-ui/core';\n`;
|
|
604
|
+
for (const imp of componentImports) {
|
|
605
|
+
output += `import ${imp.localName} from '${imp.path}';\n`;
|
|
606
|
+
}
|
|
607
|
+
output += `\n`;
|
|
608
|
+
output += `export default function mount(__target, props = {}) {\n`;
|
|
594
609
|
}
|
|
595
|
-
|
|
596
|
-
output += `\n`;
|
|
597
|
-
output += `export default function mount(__target, props = {}) {\n`;
|
|
598
610
|
output += ` const __ctx = pushContext();\n\n`;
|
|
599
611
|
|
|
600
612
|
if (hasStyles) {
|
|
@@ -618,12 +630,14 @@ export function compile(source, options = {}) {
|
|
|
618
630
|
|
|
619
631
|
output += `\n __flush_mounts();\n`;
|
|
620
632
|
output += `\n return () => {\n`;
|
|
621
|
-
output += ` // Cleanup\n`;
|
|
622
633
|
output += ` __flush_destroys();\n`;
|
|
623
634
|
output += ` popContext(__ctx);\n`;
|
|
624
635
|
output += ` __target.innerHTML = '';\n`;
|
|
625
636
|
output += ` };\n`;
|
|
626
|
-
output += `}
|
|
637
|
+
output += `};\n`;
|
|
638
|
+
if (target === 'iife') {
|
|
639
|
+
output += `})();\n`;
|
|
640
|
+
}
|
|
627
641
|
|
|
628
642
|
return {
|
|
629
643
|
code: output,
|