@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
package/build/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,109 +26,102 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
27
|
};
|
|
24
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.generateKomaciModule = void 0;
|
|
29
|
+
exports.processGeneratorInputAndState = exports.generateKomaciModule = void 0;
|
|
26
30
|
const generator_1 = __importDefault(require("@babel/generator"));
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
31
|
+
const componentAstProcessing_1 = require("./componentAstProcessing");
|
|
32
|
+
const functionAstGeneration_1 = require("./functionAstGeneration");
|
|
33
|
+
const types_1 = require("./types");
|
|
30
34
|
const t = __importStar(require("@babel/types"));
|
|
35
|
+
const genericAstGeneration_1 = require("./genericAstGeneration");
|
|
36
|
+
const common_shared_1 = require("@komaci/common-shared");
|
|
31
37
|
// Generate a module adhering to the Komaci Runtime Format which is used
|
|
32
38
|
// by the Komaci Resolution Engine to drive dependency resolution.
|
|
33
39
|
function generateKomaciModule(input) {
|
|
34
|
-
// Initial state for this call to module generator.
|
|
35
|
-
const generatorState = {
|
|
36
|
-
input,
|
|
37
|
-
adgImportSuffix: 0,
|
|
38
|
-
importAliasSuffix: 0,
|
|
39
|
-
scriptGenState: {
|
|
40
|
-
importRefsMap: {},
|
|
41
|
-
requiredFactoryFunctions: new Set(),
|
|
42
|
-
importInfosForWireAdapter: new Set(),
|
|
43
|
-
primingAdapterImportDeclarations: [],
|
|
44
|
-
},
|
|
45
|
-
templateGenState: {
|
|
46
|
-
importRefsMap: {},
|
|
47
|
-
requiredFactoryFunctions: new Set(),
|
|
48
|
-
refProps: new Set(),
|
|
49
|
-
},
|
|
50
|
-
iterationContext: [],
|
|
51
|
-
defaultCompImported: false,
|
|
52
|
-
adgNameMap: {},
|
|
53
|
-
isDefaultExportFound: false,
|
|
54
|
-
};
|
|
55
40
|
try {
|
|
56
|
-
|
|
41
|
+
return processGeneratorInputAndState(input);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
const moduleMetadata = (0, common_shared_1.initModuleMetadataObject)();
|
|
45
|
+
const babelOutput = (0, generator_1.default)(t.file((0, functionAstGeneration_1.produceErrorAdgFunction)(moduleMetadata, e)));
|
|
46
|
+
return babelOutput.code;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.generateKomaciModule = generateKomaciModule;
|
|
50
|
+
/**
|
|
51
|
+
* Helper function to process and build the resolvable module based off the generator input and inital generator state.
|
|
52
|
+
* @param input the Generator input
|
|
53
|
+
* @returns the resolvable module.
|
|
54
|
+
*/
|
|
55
|
+
function processGeneratorInputAndState(input) {
|
|
56
|
+
if (input.moduleInfo.type === 'file') {
|
|
57
|
+
// Determine file type based on extension in file name.
|
|
58
|
+
const segments = input.moduleInfo.fileName.split('.');
|
|
59
|
+
if (segments.length < 2) {
|
|
60
|
+
throw new Error(types_1.ERROR_PREFIX + 'unable to determine file type');
|
|
61
|
+
}
|
|
62
|
+
const fileExt = segments[segments.length - 1];
|
|
63
|
+
let sourceFile;
|
|
64
|
+
const source = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
65
|
+
if (fileExt === 'html') {
|
|
66
|
+
sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, undefined, input.moduleInfo.komaciDoc, source);
|
|
67
|
+
}
|
|
68
|
+
else if (fileExt === 'js') {
|
|
69
|
+
sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, input.moduleInfo.komaciDoc, undefined, source);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
throw new Error(types_1.ERROR_PREFIX + 'unsupported file extension: ' + fileExt);
|
|
73
|
+
}
|
|
74
|
+
const babelOutput = (0, generator_1.default)(sourceFile);
|
|
75
|
+
return babelOutput.code;
|
|
76
|
+
}
|
|
77
|
+
else if (input.moduleInfo.type === 'bundle') {
|
|
78
|
+
// code to process a bundle
|
|
79
|
+
let filename = '', fileExt;
|
|
80
|
+
const docMap = input.moduleInfo.files; // {'test.html' : KomaciDoc1, 'test.js' : KomaciDoc2}
|
|
81
|
+
const filesMap = {}; // {'html' : {'test.html' : KomaciDoc1}, 'js' : {'test.js' : KomaciDoc2 }}
|
|
82
|
+
let sourceFile;
|
|
83
|
+
for (const [fullFilename, komaciDoc] of Object.entries(docMap)) {
|
|
57
84
|
// Determine file type based on extension in file name.
|
|
58
|
-
const segments =
|
|
85
|
+
const segments = fullFilename.split('.');
|
|
59
86
|
if (segments.length < 2) {
|
|
60
|
-
throw new Error(
|
|
87
|
+
throw new Error(types_1.ERROR_PREFIX + 'unable to determine file type');
|
|
88
|
+
}
|
|
89
|
+
filename = segments[0]; // the filename, up to but not including, the file separator character
|
|
90
|
+
fileExt = segments[segments.length - 1]; // filename extension, not including the separator
|
|
91
|
+
if (filename !== input.moduleInfo.name) {
|
|
92
|
+
continue; // ignore files whose name do not match moduleInfo.name
|
|
93
|
+
}
|
|
94
|
+
let filesObj = {};
|
|
95
|
+
// check for existing map entry in order to append to it
|
|
96
|
+
// to support multiple files per filetype in the future
|
|
97
|
+
if (filesMap[fileExt]) {
|
|
98
|
+
filesObj = filesMap[fileExt];
|
|
61
99
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
sourceFile = (0, modGenTemplate_1.generateTemplateModule)(generatorState, input.moduleInfo.komaciDoc);
|
|
100
|
+
filesObj[filename] = komaciDoc;
|
|
101
|
+
if (fileExt == 'html') {
|
|
102
|
+
filesMap['html'] = filesObj;
|
|
66
103
|
}
|
|
67
104
|
else if (fileExt === 'js') {
|
|
68
|
-
|
|
105
|
+
filesMap['js'] = filesObj;
|
|
69
106
|
}
|
|
70
107
|
else {
|
|
71
|
-
throw new Error(
|
|
108
|
+
throw new Error(types_1.ERROR_PREFIX + 'unsupported file extension: ' + fileExt);
|
|
72
109
|
}
|
|
73
|
-
const babelOutput = (0, generator_1.default)(sourceFile);
|
|
74
|
-
return babelOutput.code;
|
|
75
110
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
filename = segments[0]; // the filename, up to but not including, the file separator character
|
|
89
|
-
fileExt = segments[segments.length - 1]; // filename extension, not including the separator
|
|
90
|
-
if (filename !== input.moduleInfo.name) {
|
|
91
|
-
continue; // ignore files whose name do not match moduleInfo.name
|
|
92
|
-
}
|
|
93
|
-
let filesObj = {};
|
|
94
|
-
// check for existing map entry in order to append to it
|
|
95
|
-
// to support multiple files per filetype in the future
|
|
96
|
-
if (filesMap[fileExt]) {
|
|
97
|
-
filesObj = filesMap[fileExt];
|
|
98
|
-
}
|
|
99
|
-
filesObj[filename] = komaciDoc;
|
|
100
|
-
if (fileExt == 'html') {
|
|
101
|
-
filesMap['html'] = filesObj;
|
|
102
|
-
}
|
|
103
|
-
else if (fileExt === 'js') {
|
|
104
|
-
filesMap['js'] = filesObj;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
throw new Error(shared_1.ERROR_PREFIX + 'unsupported file extension: ' + fileExt);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const komaciJSDoc = filesMap && filesMap['js'] && filesMap['js'][input.moduleInfo.name]
|
|
111
|
-
? filesMap['js'][input.moduleInfo.name]
|
|
112
|
-
: {};
|
|
113
|
-
const komaciHTMLDoc = filesMap && filesMap['html'] && filesMap['html'][input.moduleInfo.name]
|
|
114
|
-
? filesMap['html'][input.moduleInfo.name]
|
|
115
|
-
: {};
|
|
116
|
-
// eslint-disable-next-line prefer-const
|
|
117
|
-
sourceFile = (0, modGenScript_1.generateCombinedModule)(generatorState, komaciJSDoc, komaciHTMLDoc);
|
|
118
|
-
// Generate source from constructed AST.
|
|
119
|
-
const babelOutput = (0, generator_1.default)(sourceFile);
|
|
120
|
-
return babelOutput.code;
|
|
121
|
-
}
|
|
122
|
-
throw new Error(shared_1.ERROR_PREFIX + 'unrecognized input type');
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
const babelOutput = (0, generator_1.default)(t.file((0, modGenScript_1.produceErrorAdgFunction)(generatorState, e)));
|
|
111
|
+
const source = (0, componentAstProcessing_1.getComponentSrcJs)(input);
|
|
112
|
+
const komaciJSDoc = filesMap && filesMap['js'] && filesMap['js'][input.moduleInfo.name]
|
|
113
|
+
? filesMap['js'][input.moduleInfo.name]
|
|
114
|
+
: {};
|
|
115
|
+
const komaciHTMLDoc = filesMap && filesMap['html'] && filesMap['html'][input.moduleInfo.name]
|
|
116
|
+
? filesMap['html'][input.moduleInfo.name]
|
|
117
|
+
: {};
|
|
118
|
+
// eslint-disable-next-line prefer-const
|
|
119
|
+
sourceFile = (0, genericAstGeneration_1.generateResolvableModule)(input, komaciJSDoc, komaciHTMLDoc, source);
|
|
120
|
+
// Generate source from constructed AST.
|
|
121
|
+
const babelOutput = (0, generator_1.default)(sourceFile);
|
|
126
122
|
return babelOutput.code;
|
|
127
123
|
}
|
|
124
|
+
throw new Error(types_1.ERROR_PREFIX + 'unrecognized input type');
|
|
128
125
|
}
|
|
129
|
-
exports.
|
|
126
|
+
exports.processGeneratorInputAndState = processGeneratorInputAndState;
|
|
130
127
|
//# sourceMappingURL=index.js.map
|
package/build/types.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import * as t from '@babel/types';
|
|
2
2
|
import { KomaciDocument } from '@komaci/types';
|
|
3
|
-
import {
|
|
3
|
+
import { IdKeys } from '@komaci/common-shared';
|
|
4
|
+
export declare const ERROR_PREFIX = "[komaci esm-generator] ";
|
|
5
|
+
export declare const CONTEXT = "ctx";
|
|
6
|
+
export declare const PROPS = "props";
|
|
7
|
+
export declare const ADG_IMPORT_SUFFIX = "getAdgDefinition";
|
|
8
|
+
export declare const UNRESOLVED = "unresolved";
|
|
9
|
+
export declare const USER_VARIABLE_PREFIX = "user_var_";
|
|
10
|
+
export declare const WIRE_FUNCTION = "WireFunction";
|
|
11
|
+
export declare const GETTER_FUNCTION = "GetterFunction";
|
|
12
|
+
export declare const ERROR_FUNCTION = "ErrorFunction";
|
|
13
|
+
export declare const PRIMING_FUNCTION = "PrimingFunction";
|
|
14
|
+
export declare const ID: Record<IdKeys, t.Identifier>;
|
|
4
15
|
export declare type GeneratorInput = {
|
|
5
16
|
moduleInfo: ModuleFileInfo | ModuleBundleInfo;
|
|
6
17
|
options?: GeneratorOptions;
|
|
@@ -38,7 +49,7 @@ export declare type GeneratorState = {
|
|
|
38
49
|
importRefsMap: {
|
|
39
50
|
[refId: string]: ImportInfo;
|
|
40
51
|
};
|
|
41
|
-
importMetadata?:
|
|
52
|
+
importMetadata?: unknown;
|
|
42
53
|
importInfosForWireAdapter: Set<ImportInfo>;
|
|
43
54
|
requiredFactoryFunctions: Set<t.Identifier>;
|
|
44
55
|
primingAdapterImportDeclarations: t.ImportDeclaration[];
|
package/build/types.js
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportUsageState = void 0;
|
|
26
|
+
exports.ImportUsageState = exports.ID = exports.PRIMING_FUNCTION = exports.ERROR_FUNCTION = exports.GETTER_FUNCTION = exports.WIRE_FUNCTION = exports.USER_VARIABLE_PREFIX = exports.UNRESOLVED = exports.ADG_IMPORT_SUFFIX = exports.PROPS = exports.CONTEXT = exports.ERROR_PREFIX = void 0;
|
|
27
|
+
const t = __importStar(require("@babel/types"));
|
|
28
|
+
//////////////////////////////////////////////////////////////
|
|
29
|
+
// Types for interacting with Komaci Module Generator.
|
|
30
|
+
/////////////////////////////////////////////////////////////
|
|
31
|
+
exports.ERROR_PREFIX = '[komaci esm-generator] ';
|
|
32
|
+
exports.CONTEXT = 'ctx';
|
|
33
|
+
exports.PROPS = 'props';
|
|
34
|
+
exports.ADG_IMPORT_SUFFIX = 'getAdgDefinition';
|
|
35
|
+
exports.UNRESOLVED = 'unresolved';
|
|
36
|
+
exports.USER_VARIABLE_PREFIX = 'user_var_';
|
|
37
|
+
exports.WIRE_FUNCTION = 'WireFunction';
|
|
38
|
+
exports.GETTER_FUNCTION = 'GetterFunction';
|
|
39
|
+
exports.ERROR_FUNCTION = 'ErrorFunction';
|
|
40
|
+
exports.PRIMING_FUNCTION = 'PrimingFunction';
|
|
41
|
+
exports.ID = {
|
|
42
|
+
CONTEXT: t.identifier(exports.CONTEXT),
|
|
43
|
+
PROPS: t.identifier(exports.PROPS),
|
|
44
|
+
FACTORY: t.identifier('fct'),
|
|
45
|
+
COMPOSED_GRAPH_FUNC: t.identifier('cg'),
|
|
46
|
+
ITERATION_FUNC: t.identifier('i'),
|
|
47
|
+
UNRESOLVED_FUNC: t.identifier('u'),
|
|
48
|
+
SLOT_FUNC: t.identifier('s'),
|
|
49
|
+
ELEMENT_FUNC: t.identifier('e'),
|
|
50
|
+
ADG_FUNC: t.identifier('adg'),
|
|
51
|
+
SLOT: t.identifier('slot'),
|
|
52
|
+
COMPONENT_ID: t.identifier('componentId'),
|
|
53
|
+
UNDEFINED: t.identifier('undefined'),
|
|
54
|
+
PROP_API: t.identifier('a'),
|
|
55
|
+
PROP_INIT: t.identifier('i'),
|
|
56
|
+
PROP_FUNC: t.identifier('f'),
|
|
57
|
+
PROP_GETTER: t.identifier('g'),
|
|
58
|
+
DEFAULT_COMP: t.identifier('comp1'),
|
|
59
|
+
FUNC_ID: t.identifier('f'),
|
|
60
|
+
FUNC_NAME: t.identifier('fN'),
|
|
61
|
+
FUNC_TYPE: t.identifier('t'),
|
|
62
|
+
FUNC_CONFIG: t.identifier('c'),
|
|
63
|
+
FUNC_INPUT: t.identifier('in'),
|
|
64
|
+
WIRE_TYPE: t.identifier('wt'),
|
|
65
|
+
UNRESOLVED_VALUE: t.identifier('unresolved'),
|
|
66
|
+
BATCH_FUNC_ID: t.identifier('b'),
|
|
67
|
+
BATCH_FUNC_NAME: t.identifier('bN'),
|
|
68
|
+
REDUCER_FUNC_ID: t.identifier('r'),
|
|
69
|
+
IMG_SRC: t.identifier('src'),
|
|
70
|
+
IMG_FUNC: t.identifier('img'),
|
|
71
|
+
};
|
|
4
72
|
// enum representing the different states of the way an Import is used
|
|
5
73
|
var ImportUsageState;
|
|
6
74
|
(function (ImportUsageState) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/esm-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "242.1.0",
|
|
4
4
|
"description": "Komaci generator for ADG ES modules",
|
|
5
5
|
"homepage": "https://komaci.dev/",
|
|
6
6
|
"repository": {
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/core": "^7.9.0",
|
|
30
30
|
"@babel/generator": "^7.9.0",
|
|
31
|
-
"@komaci/common-shared": "
|
|
32
|
-
"@komaci/static-analyzer": "
|
|
31
|
+
"@komaci/common-shared": "242.1.0",
|
|
32
|
+
"@komaci/static-analyzer": "242.1.0",
|
|
33
33
|
"o11y": "^240.7.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@babel/types": "^7.9.0",
|
|
37
|
-
"@komaci/types": "
|
|
37
|
+
"@komaci/types": "242.1.0",
|
|
38
38
|
"@lwc-platform/sfdc-lwc-compiler": "^2.18.0-240.2"
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -1,110 +0,0 @@
|
|
|
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
|
|
@@ -1,196 +0,0 @@
|
|
|
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
|