@komaci/esm-generator 240.1.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/build/__tests__/compile-generated-module-fixtures.spec.d.ts +2 -0
- package/build/__tests__/compile-generated-module-fixtures.spec.js +45 -0
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/exclude-comps-unused-import-prop/actual.js +28 -0
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.d.ts +28 -0
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +144 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.d.ts +8 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-one/actual.js +35 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.d.ts +9 -0
- package/build/__tests__/fixtures-combined-files/exclude-total-unused-import-getter-from-two/actual.js +39 -0
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-combined-files/exclude-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-combined-files/image-type/actual.d.ts +12 -0
- package/build/__tests__/fixtures-combined-files/image-type/actual.js +41 -0
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.d.ts +13 -0
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +75 -0
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.d.ts +17 -0
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +99 -0
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/include-comps-used-import-prop/actual.js +28 -0
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.d.ts +9 -0
- package/build/__tests__/fixtures-combined-files/include-template-strings/actual.js +41 -0
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.d.ts +8 -0
- package/build/__tests__/fixtures-combined-files/include-used-import-getter/actual.js +38 -0
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-combined-files/include-wire-used-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.d.ts +5 -0
- package/build/__tests__/fixtures-combined-files/unsupported-wire-from-supported-namespace/actual.js +19 -0
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.d.ts +8 -0
- package/build/__tests__/fixtures-script-files/class-extends-multiple-with-separate-imports/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports/actual.js +13 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/class-extends-separate-imports-alias/actual.js +10 -0
- package/build/__tests__/fixtures-script-files/class-props/actual.d.ts +25 -0
- package/build/__tests__/fixtures-script-files/class-props/actual.js +92 -0
- package/build/__tests__/fixtures-script-files/empty-class/actual.d.ts +3 -0
- package/build/__tests__/fixtures-script-files/empty-class/actual.js +7 -0
- package/build/__tests__/fixtures-script-files/empty-doc/actual.d.ts +1 -0
- package/build/__tests__/fixtures-script-files/empty-doc/actual.js +2 -0
- package/build/__tests__/fixtures-script-files/empty-wire/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/empty-wire/actual.js +16 -0
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-script-files/exclude-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-script-files/exports/actual.d.ts +21 -0
- package/build/__tests__/fixtures-script-files/exports/actual.js +63 -0
- package/build/__tests__/fixtures-script-files/imports/actual.d.ts +10 -0
- package/build/__tests__/fixtures-script-files/imports/actual.js +76 -0
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.d.ts +9 -0
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +59 -0
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.d.ts +6 -0
- package/build/__tests__/fixtures-script-files/include-wire-unused-import-prop/actual.js +34 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.d.ts +3 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-default/actual.js +10 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.d.ts +8 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-local/actual.js +24 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/inheritance-imports-named/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.d.ts +4 -0
- package/build/__tests__/fixtures-script-files/inheritance-parent-unresolved/actual.js +17 -0
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.d.ts +5 -0
- package/build/__tests__/fixtures-script-files/unsupported-wire-from-supported-namespace/actual.js +19 -0
- package/build/__tests__/fixtures-script-files/wire-basic/actual.d.ts +7 -0
- package/build/__tests__/fixtures-script-files/wire-basic/actual.js +30 -0
- package/build/__tests__/fixtures-script-files/wire-functions/actual.d.ts +12 -0
- package/build/__tests__/fixtures-script-files/wire-functions/actual.js +46 -0
- package/build/__tests__/fixtures-script-files/wire-imports/actual.d.ts +10 -0
- package/build/__tests__/fixtures-script-files/wire-imports/actual.js +59 -0
- package/build/__tests__/fixtures-source-code/badImportRef.d.ts +4 -0
- package/build/__tests__/fixtures-source-code/badImportRef.js +21 -0
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.d.ts +5 -0
- package/build/__tests__/fixtures-source-code/generalMockSourceCode.js +93 -0
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.d.ts +9 -0
- package/build/__tests__/general-komaci-docs/assorted-template-strings/source.js +41 -0
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.d.ts +6 -0
- package/build/__tests__/general-komaci-docs/getters-and-compositions-collisions/source.js +31 -0
- package/build/__tests__/general-komaci-docs/import-types/source.d.ts +18 -0
- package/build/__tests__/general-komaci-docs/import-types/source.js +104 -0
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.d.ts +18 -0
- package/build/__tests__/general-komaci-docs/import-types/validationStuff.js +63 -0
- package/build/__tests__/general-komaci-docs/template-component/source.d.ts +8 -0
- package/build/__tests__/general-komaci-docs/template-component/source.js +34 -0
- package/build/__tests__/index.spec.d.ts +2 -0
- package/build/__tests__/index.spec.js +124 -0
- package/build/__tests__/komaci-ast-unit.spec.d.ts +2 -0
- package/build/__tests__/komaci-ast-unit.spec.js +628 -0
- package/build/__tests__/komaci-bundle-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-bundle-module.fixtures.spec.js +75 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.js +66 -0
- package/build/__tests__/komaci-template-module.fixtures.spec.d.ts +2 -0
- package/build/__tests__/komaci-template-module.fixtures.spec.js +56 -0
- package/build/__tests__/modGenScript.spec.d.ts +2 -0
- package/build/__tests__/modGenScript.spec.js +110 -0
- package/build/__tests__/modGenTemplate.spec.d.ts +2 -0
- package/build/__tests__/modGenTemplate.spec.js +196 -0
- package/build/__tests__/shared.spec.d.ts +2 -0
- package/build/__tests__/shared.spec.js +62 -0
- package/build/__tests__/templateStrings.spec.d.ts +2 -0
- package/build/__tests__/templateStrings.spec.js +130 -0
- package/build/index.d.ts +4 -0
- package/build/index.js +130 -0
- package/build/modGenScript.d.ts +38 -0
- package/build/modGenScript.js +1027 -0
- package/build/modGenTemplate.d.ts +37 -0
- package/build/modGenTemplate.js +402 -0
- package/build/shared.d.ts +170 -0
- package/build/shared.js +588 -0
- package/build/types.d.ts +132 -0
- package/build/types.js +14 -0
- package/package.json +40 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const glob_1 = __importDefault(require("glob"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const index_1 = require("../index");
|
|
10
|
+
const FIXTURES_DIR = path_1.default.join(__dirname, 'fixtures-combined-files');
|
|
11
|
+
const INPUT_HTML_JSON_FILENAME = 'komaciHTMLDoc.json';
|
|
12
|
+
const INPUT_JS_JSON_FILENAME = 'komaciJSDoc.json';
|
|
13
|
+
const INPUT_SRC_FILE_JSON_FILENAME = 'actual.js';
|
|
14
|
+
const INPUT_SRC_FILE_HTML_FILENAME = 'actual.html';
|
|
15
|
+
const EXPECTED_JS_FILENAME = 'expected.src';
|
|
16
|
+
function generateModuleSource(komaciHTMLDoc, komaciJSDoc, srcFileMap) {
|
|
17
|
+
const filesMap = {};
|
|
18
|
+
if (komaciHTMLDoc !== null) {
|
|
19
|
+
filesMap['test.html'] = komaciHTMLDoc;
|
|
20
|
+
}
|
|
21
|
+
if (komaciJSDoc !== null) {
|
|
22
|
+
filesMap['test.js'] = komaciJSDoc;
|
|
23
|
+
}
|
|
24
|
+
// adding miscellaneous files of empty Komaci docs, to test the negative case of unexpectedly named files
|
|
25
|
+
filesMap['something.js'] = {};
|
|
26
|
+
filesMap['somethingElese.html'] = {};
|
|
27
|
+
const input = {
|
|
28
|
+
moduleInfo: {
|
|
29
|
+
name: 'test',
|
|
30
|
+
namespace: 'c',
|
|
31
|
+
type: 'bundle',
|
|
32
|
+
files: filesMap,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
input.srcFileMap = srcFileMap;
|
|
36
|
+
return (0, index_1.generateKomaciModule)(input);
|
|
37
|
+
}
|
|
38
|
+
describe('fixtures', () => {
|
|
39
|
+
// find all folder paths containing a file whose name ends in ".src"
|
|
40
|
+
const fixtures = glob_1.default.sync(path_1.default.resolve(FIXTURES_DIR, '**/*.src'));
|
|
41
|
+
for (const caseEntry of fixtures) {
|
|
42
|
+
const caseFolder = path_1.default.dirname(caseEntry);
|
|
43
|
+
const caseName = path_1.default.relative(FIXTURES_DIR, caseFolder);
|
|
44
|
+
const fixtureFilePath = (fileName) => {
|
|
45
|
+
return path_1.default.join(caseFolder, fileName);
|
|
46
|
+
};
|
|
47
|
+
const readFixtureFile = (fileName) => {
|
|
48
|
+
const filePath = fixtureFilePath(fileName);
|
|
49
|
+
return fs_1.default.existsSync(filePath) ? fs_1.default.readFileSync(filePath, 'utf-8') : null;
|
|
50
|
+
};
|
|
51
|
+
const writeFixtureFile = (fileName, content) => {
|
|
52
|
+
const filePath = fixtureFilePath(fileName);
|
|
53
|
+
fs_1.default.writeFileSync(filePath, content, { encoding: 'utf-8' });
|
|
54
|
+
};
|
|
55
|
+
it(`${caseName}`, () => {
|
|
56
|
+
const src1 = readFixtureFile(INPUT_HTML_JSON_FILENAME);
|
|
57
|
+
const src2 = readFixtureFile(INPUT_JS_JSON_FILENAME);
|
|
58
|
+
const srcFileMap = {};
|
|
59
|
+
srcFileMap['test.js'] = readFixtureFile(INPUT_SRC_FILE_JSON_FILENAME);
|
|
60
|
+
srcFileMap['test.html'] = readFixtureFile(INPUT_SRC_FILE_HTML_FILENAME);
|
|
61
|
+
const komaciHTMLDoc = JSON.parse(src1);
|
|
62
|
+
const komaciJSDoc = JSON.parse(src2);
|
|
63
|
+
const actualModuleSrc = generateModuleSource(komaciHTMLDoc, komaciJSDoc, srcFileMap);
|
|
64
|
+
let expectedModuleSrc = readFixtureFile(EXPECTED_JS_FILENAME);
|
|
65
|
+
if (expectedModuleSrc == null) {
|
|
66
|
+
// write file if doesn't exist (ie new fixture)
|
|
67
|
+
expectedModuleSrc = actualModuleSrc;
|
|
68
|
+
writeFixtureFile(EXPECTED_JS_FILENAME, expectedModuleSrc);
|
|
69
|
+
}
|
|
70
|
+
// check that the actual newly generated mod source matches expected
|
|
71
|
+
expect(actualModuleSrc).toEqual(expectedModuleSrc);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=komaci-bundle-module.fixtures.spec.js.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const glob_1 = __importDefault(require("glob"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const index_1 = require("../index");
|
|
10
|
+
const FIXTURES_DIR = path_1.default.join(__dirname, 'fixtures-script-files');
|
|
11
|
+
const INPUT_JSON_FILENAME = 'komaciDoc.json';
|
|
12
|
+
const EXPECTED_JS_FILENAME = 'expected.src';
|
|
13
|
+
function generateModuleSource(komaciDoc, actualSrc) {
|
|
14
|
+
const input = {
|
|
15
|
+
moduleInfo: {
|
|
16
|
+
name: 'test',
|
|
17
|
+
namespace: 'c',
|
|
18
|
+
type: 'file',
|
|
19
|
+
fileName: 'test.js',
|
|
20
|
+
komaciDoc,
|
|
21
|
+
},
|
|
22
|
+
srcFileMap: {
|
|
23
|
+
'test.css': 'p { text-align: center; }',
|
|
24
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
if (actualSrc) {
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
29
|
+
input.srcFileMap['test.js'] = actualSrc;
|
|
30
|
+
}
|
|
31
|
+
return (0, index_1.generateKomaciModule)(input);
|
|
32
|
+
}
|
|
33
|
+
describe('fixtures', () => {
|
|
34
|
+
const fixtures = glob_1.default.sync(path_1.default.resolve(FIXTURES_DIR, '**/*.json'));
|
|
35
|
+
for (const caseEntry of fixtures) {
|
|
36
|
+
const caseFolder = path_1.default.dirname(caseEntry);
|
|
37
|
+
const caseName = path_1.default.relative(FIXTURES_DIR, caseFolder);
|
|
38
|
+
const fixtureFilePath = (fileName) => {
|
|
39
|
+
return path_1.default.join(caseFolder, fileName);
|
|
40
|
+
};
|
|
41
|
+
const readFixtureFile = (fileName) => {
|
|
42
|
+
const filePath = fixtureFilePath(fileName);
|
|
43
|
+
return fs_1.default.existsSync(filePath)
|
|
44
|
+
? fs_1.default.readFileSync(filePath, 'utf-8')
|
|
45
|
+
: undefined;
|
|
46
|
+
};
|
|
47
|
+
const writeFixtureFile = (fileName, content) => {
|
|
48
|
+
const filePath = fixtureFilePath(fileName);
|
|
49
|
+
fs_1.default.writeFileSync(filePath, content, { encoding: 'utf-8' });
|
|
50
|
+
};
|
|
51
|
+
it(`${caseName}`, () => {
|
|
52
|
+
const src = readFixtureFile(INPUT_JSON_FILENAME);
|
|
53
|
+
const komaciDoc = JSON.parse(src);
|
|
54
|
+
const actualModuleSrc = generateModuleSource(komaciDoc, readFixtureFile('actual.js'));
|
|
55
|
+
let expectedModuleSrc = readFixtureFile(EXPECTED_JS_FILENAME);
|
|
56
|
+
if (expectedModuleSrc === null) {
|
|
57
|
+
// write file if doesn't exist (ie new fixture)
|
|
58
|
+
expectedModuleSrc = actualModuleSrc;
|
|
59
|
+
writeFixtureFile(EXPECTED_JS_FILENAME, expectedModuleSrc);
|
|
60
|
+
}
|
|
61
|
+
// check that the actual newly generated mod source matches expected
|
|
62
|
+
expect(actualModuleSrc).toEqual(expectedModuleSrc);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=komaci-script-module.fixtures.spec.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const glob_1 = __importDefault(require("glob"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const index_1 = require("../index");
|
|
10
|
+
const FIXTURES_DIR = path_1.default.join(__dirname, 'fixtures-template-files');
|
|
11
|
+
const INPUT_JSON_FILENAME = 'komaciDoc.json';
|
|
12
|
+
const EXPECTED_JS_FILENAME = 'expected.src';
|
|
13
|
+
function generateModuleSource(komaciDoc) {
|
|
14
|
+
const input = {
|
|
15
|
+
moduleInfo: {
|
|
16
|
+
name: 'test',
|
|
17
|
+
namespace: 'c',
|
|
18
|
+
type: 'file',
|
|
19
|
+
fileName: 'test.html',
|
|
20
|
+
komaciDoc,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
return (0, index_1.generateKomaciModule)(input);
|
|
24
|
+
}
|
|
25
|
+
describe('fixtures', () => {
|
|
26
|
+
const fixtures = glob_1.default.sync(path_1.default.resolve(FIXTURES_DIR, '**/*.json'));
|
|
27
|
+
for (const caseEntry of fixtures) {
|
|
28
|
+
const caseFolder = path_1.default.dirname(caseEntry);
|
|
29
|
+
const caseName = path_1.default.relative(FIXTURES_DIR, caseFolder);
|
|
30
|
+
const fixtureFilePath = (fileName) => {
|
|
31
|
+
return path_1.default.join(caseFolder, fileName);
|
|
32
|
+
};
|
|
33
|
+
const readFixtureFile = (fileName) => {
|
|
34
|
+
const filePath = fixtureFilePath(fileName);
|
|
35
|
+
return fs_1.default.existsSync(filePath) ? fs_1.default.readFileSync(filePath, 'utf-8') : null;
|
|
36
|
+
};
|
|
37
|
+
const writeFixtureFile = (fileName, content) => {
|
|
38
|
+
const filePath = fixtureFilePath(fileName);
|
|
39
|
+
fs_1.default.writeFileSync(filePath, content, { encoding: 'utf-8' });
|
|
40
|
+
};
|
|
41
|
+
it(`${caseName}`, () => {
|
|
42
|
+
const src = readFixtureFile(INPUT_JSON_FILENAME);
|
|
43
|
+
const komaciDoc = JSON.parse(src);
|
|
44
|
+
const actualModuleSrc = generateModuleSource(komaciDoc);
|
|
45
|
+
let expectedModuleSrc = readFixtureFile(EXPECTED_JS_FILENAME);
|
|
46
|
+
if (expectedModuleSrc === null) {
|
|
47
|
+
// write file if doesn't exist (ie new fixture)
|
|
48
|
+
expectedModuleSrc = actualModuleSrc;
|
|
49
|
+
writeFixtureFile(EXPECTED_JS_FILENAME, expectedModuleSrc);
|
|
50
|
+
}
|
|
51
|
+
// check that the actual newly generated mod source matches expected
|
|
52
|
+
expect(actualModuleSrc).toEqual(expectedModuleSrc);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
//# sourceMappingURL=komaci-template-module.fixtures.spec.js.map
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const modGenScript_1 = require("../modGenScript");
|
|
9
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
10
|
+
const types_1 = require("@babel/types");
|
|
11
|
+
const initGeneratorState = (input) => ({
|
|
12
|
+
input,
|
|
13
|
+
adgImportSuffix: 0,
|
|
14
|
+
importAliasSuffix: 0,
|
|
15
|
+
scriptGenState: {
|
|
16
|
+
importRefsMap: {},
|
|
17
|
+
requiredFactoryFunctions: new Set([]),
|
|
18
|
+
importInfosForWireAdapter: new Set([]),
|
|
19
|
+
primingAdapterImportDeclarations: [],
|
|
20
|
+
},
|
|
21
|
+
templateGenState: {
|
|
22
|
+
importRefsMap: {},
|
|
23
|
+
requiredFactoryFunctions: new Set(),
|
|
24
|
+
refProps: new Set(),
|
|
25
|
+
},
|
|
26
|
+
iterationContext: [],
|
|
27
|
+
defaultCompImported: true,
|
|
28
|
+
adgNameMap: {},
|
|
29
|
+
isDefaultExportFound: true,
|
|
30
|
+
});
|
|
31
|
+
describe('generateScriptModule', () => {
|
|
32
|
+
it('should not process items requiring the AST if the source is not provided', () => {
|
|
33
|
+
const komaciDoc = JSON.parse(fs_1.default.readFileSync((0, path_1.join)(__dirname, './fixtures-script-files/class-props/komaciDoc.json'), 'utf-8'));
|
|
34
|
+
const filesMap = {};
|
|
35
|
+
filesMap['test.js'] = komaciDoc;
|
|
36
|
+
const input = {
|
|
37
|
+
moduleInfo: {
|
|
38
|
+
name: 'test',
|
|
39
|
+
namespace: 'lightning',
|
|
40
|
+
type: 'bundle',
|
|
41
|
+
files: filesMap,
|
|
42
|
+
},
|
|
43
|
+
srcFileMap: {
|
|
44
|
+
'somethingElse.js': 'eval("bye")',
|
|
45
|
+
'test.css': 'p { text-align: center; }',
|
|
46
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const generatorState = initGeneratorState(input);
|
|
50
|
+
(0, modGenScript_1.generateScriptModule)(generatorState, komaciDoc);
|
|
51
|
+
expect(komaciDoc.adgs?.[0].functions?.find((f) => f.type === 'GetterFunction')).toBeUndefined();
|
|
52
|
+
});
|
|
53
|
+
it('should process items requiring ast if the source is provided', () => {
|
|
54
|
+
const src = fs_1.default.readFileSync((0, path_1.join)(__dirname, './fixtures-script-files/class-props/actual.js'), 'utf-8');
|
|
55
|
+
const komaciDoc = JSON.parse(fs_1.default.readFileSync((0, path_1.join)(__dirname, './fixtures-script-files/class-props/komaciDoc.json'), 'utf-8'));
|
|
56
|
+
const filesMap = {};
|
|
57
|
+
filesMap['test.js'] = komaciDoc;
|
|
58
|
+
const input = {
|
|
59
|
+
moduleInfo: {
|
|
60
|
+
name: 'test',
|
|
61
|
+
namespace: 'lightning',
|
|
62
|
+
type: 'bundle',
|
|
63
|
+
files: filesMap,
|
|
64
|
+
},
|
|
65
|
+
srcFileMap: {
|
|
66
|
+
'test.js': src,
|
|
67
|
+
'test.css': 'p { text-align: center; }',
|
|
68
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
const generatorState = initGeneratorState(input);
|
|
72
|
+
(0, modGenScript_1.generateScriptModule)(generatorState, komaciDoc);
|
|
73
|
+
expect(komaciDoc.adgs?.[0].functions?.find((f) => f.type === 'GetterFunction')).not.toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
describe('produceErrorAdgFunction', () => {
|
|
77
|
+
it('should produce a resolvable module with an adg with only one node that shows what the error was', () => {
|
|
78
|
+
const input = {
|
|
79
|
+
moduleInfo: {
|
|
80
|
+
name: 'test',
|
|
81
|
+
namespace: 'lightning',
|
|
82
|
+
type: 'bundle',
|
|
83
|
+
files: {},
|
|
84
|
+
},
|
|
85
|
+
srcFileMap: {
|
|
86
|
+
'test.js': '',
|
|
87
|
+
'test.css': 'p { text-align: center; }',
|
|
88
|
+
'test.html': '<html><body><h1>Hey</h1></body></html>',
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
const generatorState = initGeneratorState(input);
|
|
92
|
+
const expected = `export default function (fct, ctx) {
|
|
93
|
+
const {
|
|
94
|
+
adg
|
|
95
|
+
} = fct;
|
|
96
|
+
return adg(undefined, {}, [{
|
|
97
|
+
t: "ErrorFunction",
|
|
98
|
+
c: {
|
|
99
|
+
"error": "something bad happened",
|
|
100
|
+
"stack": "full stack normally"
|
|
101
|
+
}
|
|
102
|
+
}], comp1, []);
|
|
103
|
+
}`;
|
|
104
|
+
const testError = new Error('something bad happened');
|
|
105
|
+
testError.stack = 'full stack normally';
|
|
106
|
+
const res = (0, modGenScript_1.produceErrorAdgFunction)(generatorState, testError);
|
|
107
|
+
expect((0, generator_1.default)((0, types_1.file)(res)).code).toBe(expected);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=modGenScript.spec.js.map
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const modGenTemplate_1 = require("../modGenTemplate");
|
|
4
|
+
const types_1 = require("@babel/types");
|
|
5
|
+
const shared_1 = require("../shared");
|
|
6
|
+
const initGeneratorState = (input) => ({
|
|
7
|
+
input,
|
|
8
|
+
adgImportSuffix: 0,
|
|
9
|
+
importAliasSuffix: 0,
|
|
10
|
+
scriptGenState: {
|
|
11
|
+
importRefsMap: {},
|
|
12
|
+
requiredFactoryFunctions: new Set([]),
|
|
13
|
+
importInfosForWireAdapter: new Set([]),
|
|
14
|
+
primingAdapterImportDeclarations: [],
|
|
15
|
+
},
|
|
16
|
+
templateGenState: {
|
|
17
|
+
importRefsMap: {},
|
|
18
|
+
requiredFactoryFunctions: new Set(),
|
|
19
|
+
refProps: new Set(),
|
|
20
|
+
},
|
|
21
|
+
iterationContext: [],
|
|
22
|
+
defaultCompImported: true,
|
|
23
|
+
adgNameMap: {},
|
|
24
|
+
isDefaultExportFound: true,
|
|
25
|
+
});
|
|
26
|
+
const generatorInput = {
|
|
27
|
+
moduleInfo: {
|
|
28
|
+
name: 'test',
|
|
29
|
+
namespace: 'lightning',
|
|
30
|
+
komaciDoc: {},
|
|
31
|
+
fileName: 'test.html',
|
|
32
|
+
type: 'file',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
describe('imageToExpression', () => {
|
|
36
|
+
it('should return an expression for a KomaciDocument Image node', () => {
|
|
37
|
+
const komaciDocImagePrimitive = {
|
|
38
|
+
type: 'Image',
|
|
39
|
+
src: {
|
|
40
|
+
type: 'PrimitiveValue',
|
|
41
|
+
value: 'testPrimitive.jpg', // this is string literal of a relative URL
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
const generatorState = initGeneratorState(generatorInput);
|
|
45
|
+
let expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImagePrimitive);
|
|
46
|
+
expect(expression.type).toBe('CallExpression');
|
|
47
|
+
let callExpression = expression;
|
|
48
|
+
expect(callExpression).not.toBeUndefined();
|
|
49
|
+
expect(callExpression.callee).toBe(shared_1.ID.IMG_FUNC);
|
|
50
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
51
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
52
|
+
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
53
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
54
|
+
let objExpression = callExpression
|
|
55
|
+
.arguments[0];
|
|
56
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
57
|
+
expect(objExpression.properties).toHaveLength(1);
|
|
58
|
+
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
59
|
+
let objProperty = objExpression.properties[0];
|
|
60
|
+
expect(objProperty.key).toBe(shared_1.ID.IMG_SRC);
|
|
61
|
+
expect(objProperty.value).toEqual((0, types_1.stringLiteral)('testPrimitive.jpg')); // img({src: "testPrimitive.jpg"})
|
|
62
|
+
const komaciDocImageBinding = {
|
|
63
|
+
type: 'Image',
|
|
64
|
+
src: {
|
|
65
|
+
type: 'Binding',
|
|
66
|
+
value: 'testBinding', // this is a string literal, but represents a variable name
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImageBinding);
|
|
70
|
+
expect(expression.type).toBe('CallExpression');
|
|
71
|
+
callExpression = expression;
|
|
72
|
+
expect(callExpression).not.toBeUndefined();
|
|
73
|
+
expect(callExpression.callee).toBe(shared_1.ID.IMG_FUNC);
|
|
74
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
75
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
76
|
+
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
77
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
78
|
+
objExpression = callExpression.arguments[0];
|
|
79
|
+
expect(objExpression).not.toBeUndefined();
|
|
80
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
81
|
+
expect(objExpression.properties).toHaveLength(1);
|
|
82
|
+
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
83
|
+
objProperty = objExpression.properties[0];
|
|
84
|
+
expect(objProperty.key).toBe(shared_1.ID.IMG_SRC);
|
|
85
|
+
let segments = ['ctx', 'props', 'testBinding'];
|
|
86
|
+
let expr = (0, types_1.identifier)(segments[0]);
|
|
87
|
+
for (let i = 1; i < segments.length; i++) {
|
|
88
|
+
expr = (0, types_1.optionalMemberExpression)(expr, (0, types_1.identifier)(segments[i]), false, false);
|
|
89
|
+
}
|
|
90
|
+
expect(objProperty.value).toEqual(expr); // img({src: ctx.props.testBinding})
|
|
91
|
+
const komaciDocImageNestedBinding = {
|
|
92
|
+
type: 'Image',
|
|
93
|
+
src: {
|
|
94
|
+
type: 'Binding',
|
|
95
|
+
value: 'imageObject/nested/imageName', // this is a string literal, represents nested-scoped variable names
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImageNestedBinding);
|
|
99
|
+
expect(expression.type).toBe('CallExpression');
|
|
100
|
+
callExpression = expression;
|
|
101
|
+
expect(callExpression).not.toBeUndefined();
|
|
102
|
+
expect(callExpression.callee).toBe(shared_1.ID.IMG_FUNC);
|
|
103
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
104
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
105
|
+
expect(callExpression.arguments[0]).not.toBeUndefined();
|
|
106
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
107
|
+
objExpression = callExpression.arguments[0];
|
|
108
|
+
expect(objExpression).not.toBeUndefined();
|
|
109
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
110
|
+
expect(objExpression.properties).toHaveLength(1);
|
|
111
|
+
expect(objExpression.properties[0].type).toBe('ObjectProperty');
|
|
112
|
+
objProperty = objExpression.properties[0];
|
|
113
|
+
expect(objProperty.key).toBe(shared_1.ID.IMG_SRC);
|
|
114
|
+
segments = ['ctx', 'props', 'imageObject', 'nested', 'imageName'];
|
|
115
|
+
expr = (0, types_1.identifier)(segments[0]);
|
|
116
|
+
const chainingStartIdx = 2;
|
|
117
|
+
for (let i = 1; i < segments.length; i++) {
|
|
118
|
+
expr = (0, types_1.optionalMemberExpression)(expr, (0, types_1.identifier)(segments[i]), false, i > chainingStartIdx);
|
|
119
|
+
}
|
|
120
|
+
expect(objProperty.value).toEqual(expr); // img({src: ctx.props.imageObject?.nested?.imageName})
|
|
121
|
+
});
|
|
122
|
+
it('should not return an expression for invalid KomaciDocument Image nodes due to invalid src.value type (boolean)', () => {
|
|
123
|
+
const komaciDocImagePrimitive = {
|
|
124
|
+
type: 'Image',
|
|
125
|
+
src: {
|
|
126
|
+
type: 'PrimitiveValue',
|
|
127
|
+
value: false, // not a supported type (boolean)
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
const generatorState = initGeneratorState(generatorInput);
|
|
131
|
+
const expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImagePrimitive);
|
|
132
|
+
expect(expression.type).toBe('CallExpression');
|
|
133
|
+
const callExpression = expression;
|
|
134
|
+
expect(callExpression).not.toBeUndefined();
|
|
135
|
+
expect(callExpression.callee).not.toBeUndefined();
|
|
136
|
+
expect(callExpression.callee).toBe(shared_1.ID.IMG_FUNC);
|
|
137
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
138
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
139
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
140
|
+
const objExpression = callExpression
|
|
141
|
+
.arguments[0];
|
|
142
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
143
|
+
expect(objExpression.properties).toHaveLength(0); // no img() populated with a valid src attribute
|
|
144
|
+
});
|
|
145
|
+
it('should not return an expression for invalid KomaciDocument Image nodes due to blank src.value', () => {
|
|
146
|
+
const komaciDocImagePrimitiveBlank = {
|
|
147
|
+
type: 'Image',
|
|
148
|
+
src: {
|
|
149
|
+
type: 'PrimitiveValue',
|
|
150
|
+
value: '', // blanks not supported
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
const generatorState = initGeneratorState(generatorInput);
|
|
154
|
+
let expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImagePrimitiveBlank);
|
|
155
|
+
expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImagePrimitiveBlank);
|
|
156
|
+
expect(expression.type).toBe('CallExpression');
|
|
157
|
+
const callExpression = expression;
|
|
158
|
+
expect(callExpression).not.toBeUndefined();
|
|
159
|
+
expect(callExpression.callee).not.toBeUndefined();
|
|
160
|
+
expect(callExpression.callee).toBe(shared_1.ID.IMG_FUNC);
|
|
161
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
162
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
163
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
164
|
+
const objExpression = callExpression
|
|
165
|
+
.arguments[0];
|
|
166
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
167
|
+
expect(objExpression.properties).toHaveLength(0); // no img() populated with a valid src attribute
|
|
168
|
+
});
|
|
169
|
+
it('should not return an expression for invalid KomaciDocument Image nodes with src.type that is neither Binding nor PrimitiveType', () => {
|
|
170
|
+
const komaciDocImageInvalidSrcValType = {
|
|
171
|
+
type: 'Image',
|
|
172
|
+
src: {
|
|
173
|
+
type: 'PrimitiveValue',
|
|
174
|
+
value: 'some random string',
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
const generatorState = initGeneratorState(generatorInput);
|
|
178
|
+
// change the src.value type to something invalid, a number
|
|
179
|
+
komaciDocImageInvalidSrcValType.src.value = 12345;
|
|
180
|
+
let expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImageInvalidSrcValType);
|
|
181
|
+
expression = (0, modGenTemplate_1.imageToExpression)(generatorState, komaciDocImageInvalidSrcValType);
|
|
182
|
+
expect(expression.type).toBe('CallExpression');
|
|
183
|
+
const callExpression = expression;
|
|
184
|
+
expect(callExpression).not.toBeUndefined();
|
|
185
|
+
expect(callExpression.callee).not.toBeUndefined();
|
|
186
|
+
expect(callExpression.callee).toBe(shared_1.ID.IMG_FUNC);
|
|
187
|
+
expect(callExpression.arguments).not.toBeUndefined();
|
|
188
|
+
expect(callExpression.arguments).toHaveLength(1);
|
|
189
|
+
expect(callExpression.arguments[0].type).toBe('ObjectExpression');
|
|
190
|
+
const objExpression = callExpression
|
|
191
|
+
.arguments[0];
|
|
192
|
+
expect(objExpression.properties).not.toBeUndefined();
|
|
193
|
+
expect(objExpression.properties).toHaveLength(0);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
//# sourceMappingURL=modGenTemplate.spec.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
26
|
+
const shared_1 = require("../shared");
|
|
27
|
+
const badImportRef_1 = require("./fixtures-source-code/badImportRef");
|
|
28
|
+
const t = __importStar(require("@babel/types"));
|
|
29
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
30
|
+
describe('sanitizeFunction', () => {
|
|
31
|
+
const ast = (0, common_shared_1.generateAstFromSrcCode)(badImportRef_1.sourceClass);
|
|
32
|
+
const { getters } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
33
|
+
const imports = new Map();
|
|
34
|
+
imports.set('test', {
|
|
35
|
+
identifierName: 'test',
|
|
36
|
+
namespace: 'force/shared',
|
|
37
|
+
isSupported: true,
|
|
38
|
+
isDefault: true,
|
|
39
|
+
isNamespaceSpecifier: false,
|
|
40
|
+
});
|
|
41
|
+
imports.set('bad', {
|
|
42
|
+
identifierName: 'test',
|
|
43
|
+
namespace: 'invalid/import',
|
|
44
|
+
isSupported: false,
|
|
45
|
+
isDefault: true,
|
|
46
|
+
isNamespaceSpecifier: false,
|
|
47
|
+
});
|
|
48
|
+
const generatedNameMap = new Map();
|
|
49
|
+
generatedNameMap.set('force/shared', 'i0');
|
|
50
|
+
generatedNameMap.set('invalid/import', shared_1.UNRESOLVED);
|
|
51
|
+
it('should be able to clean up and hoist a function with valid import references', () => {
|
|
52
|
+
(0, shared_1.sanitizeFunction)(getters[0], imports, generatedNameMap);
|
|
53
|
+
const hoisted = t.functionDeclaration(t.identifier('g0'), [t.identifier('props')], // make 'props' an input parameter to the hoisted getter
|
|
54
|
+
getters[0].node.body);
|
|
55
|
+
const generatedFunction = (0, generator_1.default)(t.file(t.program([hoisted])));
|
|
56
|
+
expect(generatedFunction.code).toBe(badImportRef_1.expectedGoodHoist);
|
|
57
|
+
});
|
|
58
|
+
it('should throw an error if we try to reference a bad input', () => {
|
|
59
|
+
expect(() => (0, shared_1.sanitizeFunction)(getters[1], imports, generatedNameMap)).toThrowError(new Error(`${shared_1.ERROR_PREFIX}: 'bad' does not map to valid import`));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=shared.spec.js.map
|