@komaci/esm-generator 240.1.3 → 242.1.0
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__/adgAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/adgAstGeneration.spec.js +31 -0
- package/build/__tests__/compositionAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/compositionAstGeneration.spec.js +394 -0
- package/build/__tests__/fixtures-combined-files/exclude-partial-classProps-indirect-importRef-getter/actual.js +5 -1
- package/build/__tests__/fixtures-combined-files/include-all-indirect-importRef-getter-complex/actual.js +5 -1
- package/build/__tests__/fixtures-combined-files/include-class-prop-indirect-importRef-getter/actual.js +5 -1
- package/build/__tests__/fixtures-script-files/imports/actual.js +5 -1
- package/build/__tests__/fixtures-script-files/imports-namespaced/actual.js +5 -1
- package/build/__tests__/fixtures-script-files/wire-imports/actual.js +5 -1
- package/build/__tests__/functionAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/functionAstGeneration.spec.js +412 -0
- package/build/__tests__/general-komaci-docs/import-types/source.js +5 -1
- package/build/__tests__/general-komaci-docs/template-component/source.js +3 -3
- package/build/__tests__/genericAstGeneration.spec.d.ts +2 -0
- package/build/__tests__/genericAstGeneration.spec.js +586 -0
- package/build/__tests__/index.spec.js +13 -9
- package/build/__tests__/komaci-ast-unit.spec.js +240 -448
- package/build/__tests__/komaci-bundle-module.fixtures.spec.js +1 -0
- package/build/__tests__/komaci-script-module.fixtures.spec.js +5 -1
- package/build/__tests__/komaci-template-module.fixtures.spec.js +2 -1
- package/build/componentAstProcessing.d.ts +34 -0
- package/build/componentAstProcessing.js +105 -0
- package/build/compositionAstGeneration.d.ts +76 -0
- package/build/compositionAstGeneration.js +299 -0
- package/build/functionAstGeneration.d.ts +81 -0
- package/build/functionAstGeneration.js +337 -0
- package/build/genericAstGeneration.d.ts +107 -0
- package/build/genericAstGeneration.js +600 -0
- package/build/index.d.ts +6 -0
- package/build/index.js +85 -88
- package/build/types.d.ts +13 -2
- package/build/types.js +69 -1
- package/package.json +4 -4
- package/build/__tests__/modGenScript.spec.d.ts +0 -2
- package/build/__tests__/modGenScript.spec.js +0 -110
- package/build/__tests__/modGenTemplate.spec.d.ts +0 -2
- package/build/__tests__/modGenTemplate.spec.js +0 -196
- package/build/__tests__/shared.spec.d.ts +0 -2
- package/build/__tests__/shared.spec.js +0 -62
- package/build/__tests__/templateStrings.spec.d.ts +0 -2
- package/build/__tests__/templateStrings.spec.js +0 -130
- package/build/modGenScript.d.ts +0 -38
- package/build/modGenScript.js +0 -1027
- package/build/modGenTemplate.d.ts +0 -37
- package/build/modGenTemplate.js +0 -402
- package/build/shared.d.ts +0 -170
- package/build/shared.js +0 -588
|
@@ -1,62 +0,0 @@
|
|
|
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
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const shared_1 = require("../shared");
|
|
6
|
-
const common_shared_1 = require("@komaci/common-shared");
|
|
7
|
-
const types_1 = require("@babel/types");
|
|
8
|
-
describe('updateKomaciDocumentWithValidTemplatedStrings', () => {
|
|
9
|
-
it('should add info about templates to the functions array of the default adg', () => {
|
|
10
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/assorted-template-strings');
|
|
11
|
-
const komaciDoc = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'script-komaci-doc.json'), {
|
|
12
|
-
encoding: 'utf-8',
|
|
13
|
-
}));
|
|
14
|
-
const src = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
15
|
-
encoding: 'utf-8',
|
|
16
|
-
});
|
|
17
|
-
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
18
|
-
const { templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
19
|
-
const templateStringsInfo = [
|
|
20
|
-
{
|
|
21
|
-
template: templateStrings[0],
|
|
22
|
-
generatedName: 't0',
|
|
23
|
-
memberUsage: ['basicInit'],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
template: templateStrings[1],
|
|
27
|
-
generatedName: 't1',
|
|
28
|
-
memberUsage: [],
|
|
29
|
-
},
|
|
30
|
-
];
|
|
31
|
-
(0, shared_1.updateKomaciDocumentWithValidTemplatedStrings)(komaciDoc, templateStringsInfo);
|
|
32
|
-
expect(komaciDoc.adgs?.[0].functions).toHaveLength(3);
|
|
33
|
-
expect(komaciDoc.adgs?.[0].functions?.[1].type).toBe(shared_1.TEMPLATED_STRING_FUNCTION);
|
|
34
|
-
expect(komaciDoc.adgs?.[0].functions?.[1].reference.type).toBe('InternalReference');
|
|
35
|
-
expect(komaciDoc.adgs?.[0].functions?.[1].reference.value).toBe('t0');
|
|
36
|
-
expect(komaciDoc.adgs?.[0].functions?.[2].type).toBe(shared_1.TEMPLATED_STRING_FUNCTION);
|
|
37
|
-
expect(komaciDoc.adgs?.[0].functions?.[2].reference.type).toBe('InternalReference');
|
|
38
|
-
expect(komaciDoc.adgs?.[0].functions?.[2].reference.value).toBe('t1');
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('hoistTemplateStrings', () => {
|
|
42
|
-
const baseFilesPath = (0, path_1.join)(__dirname, 'general-komaci-docs/assorted-template-strings');
|
|
43
|
-
const src = (0, fs_1.readFileSync)((0, path_1.join)(baseFilesPath, 'source.js'), {
|
|
44
|
-
encoding: 'utf-8',
|
|
45
|
-
});
|
|
46
|
-
const ast = (0, common_shared_1.generateAstFromSrcCode)(src);
|
|
47
|
-
const { templateStrings } = (0, common_shared_1.getPropertyMetadataFromAst)(ast);
|
|
48
|
-
const templateStringsInfo = [
|
|
49
|
-
{
|
|
50
|
-
template: templateStrings[0],
|
|
51
|
-
generatedName: 't0',
|
|
52
|
-
memberUsage: ['basicInit'],
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
template: templateStrings[1],
|
|
56
|
-
generatedName: 't1',
|
|
57
|
-
memberUsage: [],
|
|
58
|
-
},
|
|
59
|
-
];
|
|
60
|
-
const emptyProgram = (0, types_1.file)((0, types_1.program)([]));
|
|
61
|
-
const importReferencesMap = {
|
|
62
|
-
'1/names/0': {
|
|
63
|
-
localName: (0, types_1.identifier)('i1'),
|
|
64
|
-
resourceName: 'lightning/graphql',
|
|
65
|
-
importDeclaration: (0, types_1.importDeclaration)([(0, types_1.importSpecifier)((0, types_1.identifier)('i1'), (0, types_1.identifier)('gql'))], (0, types_1.stringLiteral)('lightning/graphql')),
|
|
66
|
-
importSpecifier: (0, types_1.importSpecifier)((0, types_1.identifier)('i1'), (0, types_1.identifier)('gql')),
|
|
67
|
-
exportName: undefined,
|
|
68
|
-
importUsages: new Set(),
|
|
69
|
-
},
|
|
70
|
-
'2/names/0': {
|
|
71
|
-
localName: (0, types_1.identifier)('i2'),
|
|
72
|
-
resourceName: 'snoop',
|
|
73
|
-
importDeclaration: (0, types_1.importDeclaration)([(0, types_1.importSpecifier)((0, types_1.identifier)('i2'), (0, types_1.identifier)('sneaky'))], (0, types_1.stringLiteral)('snoop')),
|
|
74
|
-
importSpecifier: (0, types_1.importSpecifier)((0, types_1.identifier)('i2'), (0, types_1.identifier)('sneaky')),
|
|
75
|
-
exportName: undefined,
|
|
76
|
-
importUsages: new Set(),
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
const definedImports = new Map();
|
|
80
|
-
definedImports.set('gql', {
|
|
81
|
-
isDefault: false,
|
|
82
|
-
isNamespaceSpecifier: false,
|
|
83
|
-
isSupported: true,
|
|
84
|
-
namespace: 'lightning/graphql',
|
|
85
|
-
identifierName: 'gql',
|
|
86
|
-
});
|
|
87
|
-
definedImports.set('sneaky', {
|
|
88
|
-
isDefault: false,
|
|
89
|
-
isNamespaceSpecifier: false,
|
|
90
|
-
isSupported: true,
|
|
91
|
-
namespace: 'snoop',
|
|
92
|
-
identifierName: 'sneaky',
|
|
93
|
-
});
|
|
94
|
-
(0, shared_1.hoistTemplateStrings)(emptyProgram, importReferencesMap, definedImports, templateStringsInfo);
|
|
95
|
-
it('can compose a template string for a public api prop', () => {
|
|
96
|
-
const firstFunction = emptyProgram.program.body[0];
|
|
97
|
-
expect(firstFunction.type).toBe('FunctionDeclaration');
|
|
98
|
-
expect(firstFunction.id.name).toBe('t0');
|
|
99
|
-
expect(firstFunction.body.body).toHaveLength(1);
|
|
100
|
-
expect(firstFunction.body.body[0].type).toBe('ReturnStatement');
|
|
101
|
-
expect(firstFunction.body.body[0]
|
|
102
|
-
.argument?.type).toBe('TemplateLiteral');
|
|
103
|
-
expect(firstFunction.body.body[0]
|
|
104
|
-
.argument.expressions).toHaveLength(2);
|
|
105
|
-
expect(firstFunction.body.body[0]
|
|
106
|
-
.argument.expressions[0].type).toBe('MemberExpression');
|
|
107
|
-
expect(firstFunction.body
|
|
108
|
-
.body[0].argument.expressions[0].object.name).toBe('props');
|
|
109
|
-
expect(firstFunction.body
|
|
110
|
-
.body[0].argument.expressions[0].property.name).toBe('basicInit');
|
|
111
|
-
expect(firstFunction.body.body[0]
|
|
112
|
-
.argument.expressions[1].type).toBe('Identifier');
|
|
113
|
-
expect(firstFunction.body
|
|
114
|
-
.body[0].argument.expressions[1].name).toBe('i2');
|
|
115
|
-
});
|
|
116
|
-
it('can compose a template string for an internal prop', () => {
|
|
117
|
-
const firstFunction = emptyProgram.program.body[1];
|
|
118
|
-
expect(firstFunction.type).toBe('FunctionDeclaration');
|
|
119
|
-
expect(firstFunction.id.name).toBe('t1');
|
|
120
|
-
expect(firstFunction.body.body).toHaveLength(1);
|
|
121
|
-
expect(firstFunction.body.body[0].type).toBe('ReturnStatement');
|
|
122
|
-
expect(firstFunction.body.body[0]
|
|
123
|
-
.argument?.type).toBe('TaggedTemplateExpression');
|
|
124
|
-
expect(firstFunction.body.body[0]
|
|
125
|
-
.argument.quasi.expressions).toHaveLength(1);
|
|
126
|
-
expect(firstFunction.body
|
|
127
|
-
.body[0].argument.tag.name).toBe('i1');
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
//# sourceMappingURL=templateStrings.spec.js.map
|
package/build/modGenScript.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as t from '@babel/types';
|
|
2
|
-
import { GeneratorState } from './types';
|
|
3
|
-
import { KomaciDocument } from '@komaci/types';
|
|
4
|
-
import { ConsumedImports } from '@komaci/common-shared';
|
|
5
|
-
/**
|
|
6
|
-
* Generate the resolvable module for a single JS Script
|
|
7
|
-
* @param {GeneratorState} generatorState the state of the ESM generator
|
|
8
|
-
* @param {KomaciDocument} komaciDoc the KomaciDocument representation of the JS Script
|
|
9
|
-
* @returns {File} babel/types File representation of the entire JS Script. In other works, the Abstract systax tree
|
|
10
|
-
* of the generated resolvable module.
|
|
11
|
-
*/
|
|
12
|
-
export declare function generateScriptModule(generatorState: GeneratorState, komaciDoc: KomaciDocument): t.File;
|
|
13
|
-
/**
|
|
14
|
-
* Given information about what imports a getter consumes, we check the komaci doc to make sure all the
|
|
15
|
-
* import info is available
|
|
16
|
-
* @param komaciScriptDoc The Komaci doc to process
|
|
17
|
-
* @param consumedImports metadata about getter import consumption
|
|
18
|
-
*/
|
|
19
|
-
export declare function updateImportsWithGetterConsumption(komaciScriptDoc: KomaciDocument, consumedImports: ConsumedImports): void;
|
|
20
|
-
/**
|
|
21
|
-
* Generates the resolvable runtime module for a script and template file.
|
|
22
|
-
* @param {GeneratorState} generatorState the state of the ESM generator
|
|
23
|
-
* @param {KomaciDocument} komaciScriptDoc the Komaci doc for the script file
|
|
24
|
-
* @param {KomaciDocument} komaciTemplateDoc the Komaci doc for the template file
|
|
25
|
-
* @returns babel/types File representing the generated, combined resolvable runtime module. In other words,
|
|
26
|
-
* the Abstract Syntax Tree of the combined, resolvable module.
|
|
27
|
-
*/
|
|
28
|
-
export declare function generateCombinedModule(generatorState: GeneratorState, komaciScriptDoc: KomaciDocument, komaciTemplateDoc: KomaciDocument): t.File;
|
|
29
|
-
/**
|
|
30
|
-
* A barebones resolvable module default export with a singular node describing the context of an error.
|
|
31
|
-
*
|
|
32
|
-
* We return this instead of a real resolvable module if something throws an error during resolvable module generation
|
|
33
|
-
* @param generatorState The state of the generator for pass through to adgToExpression
|
|
34
|
-
* @param error The error that was thrown
|
|
35
|
-
* @returns A default export representing the error state for this resolvable module
|
|
36
|
-
*/
|
|
37
|
-
export declare function produceErrorAdgFunction(generatorState: GeneratorState, error: Error): t.Program;
|
|
38
|
-
//# sourceMappingURL=modGenScript.d.ts.map
|