@ibyar/cli 2.0.2 → 2.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/README.md +2 -0
- package/bin/cli.js +7 -5
- package/bin/cli.js.map +1 -1
- package/compiler/compiler.d.ts +2 -0
- package/compiler/compiler.d.ts.map +1 -1
- package/compiler/compiler.js +10 -0
- package/compiler/compiler.js.map +1 -1
- package/directives/directives.d.ts +3 -0
- package/directives/directives.d.ts.map +1 -0
- package/directives/directives.js +48 -0
- package/directives/directives.js.map +1 -0
- package/directives/register.d.ts +9 -0
- package/directives/register.d.ts.map +1 -0
- package/directives/register.js +87 -0
- package/directives/register.js.map +1 -0
- package/package.json +8 -7
- package/transformer/after-declarations-component copy.d.ts +9 -0
- package/transformer/after-declarations-component copy.d.ts.map +1 -0
- package/transformer/after-declarations-component copy.js +56 -0
- package/transformer/after-declarations-component copy.js.map +1 -0
- package/transformer/after-declarations-component.d.ts +0 -1
- package/transformer/after-declarations-component.d.ts.map +1 -1
- package/transformer/after-declarations-component.js +4 -9
- package/transformer/after-declarations-component.js.map +1 -1
- package/transformer/after-declarations-directie.d.ts +8 -0
- package/transformer/after-declarations-directie.d.ts.map +1 -0
- package/transformer/after-declarations-directie.js +26 -0
- package/transformer/after-declarations-directie.js.map +1 -0
- package/transformer/before-component copy.d.ts +9 -0
- package/transformer/before-component copy.d.ts.map +1 -0
- package/transformer/before-component copy.js +212 -0
- package/transformer/before-component copy.js.map +1 -0
- package/transformer/before-component.d.ts +0 -7
- package/transformer/before-component.d.ts.map +1 -1
- package/transformer/before-component.js +23 -65
- package/transformer/before-component.js.map +1 -1
- package/transformer/before-directive.d.ts +8 -0
- package/transformer/before-directive.d.ts.map +1 -0
- package/transformer/before-directive.js +94 -0
- package/transformer/before-directive.js.map +1 -0
- package/transformer/factory.d.ts +21 -1
- package/transformer/factory.d.ts.map +1 -1
- package/transformer/factory.js +43 -5
- package/transformer/factory.js.map +1 -1
- package/transformer/helpers.d.ts +80 -0
- package/transformer/helpers.d.ts.map +1 -0
- package/transformer/helpers.js +141 -0
- package/transformer/helpers.js.map +1 -0
- package/transformer/modules.d.ts +8 -8
- package/transformer/modules.d.ts.map +1 -1
- package/transformer/modules.js +6 -0
- package/transformer/modules.js.map +1 -1
- package/transformer/scan-directives.d.ts +22 -0
- package/transformer/scan-directives.d.ts.map +1 -0
- package/transformer/scan-directives.js +79 -0
- package/transformer/scan-directives.js.map +1 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
import { buildExpressionNodes } from '@ibyar/core/node';
|
|
3
|
+
import { htmlParser, directiveRegistry } from '@ibyar/elements/node';
|
|
4
|
+
import { getExtendsTypeBySelector } from '../elements/tags.js';
|
|
5
|
+
import { createConstructorOfViewInterfaceDeclaration, convertToProperties, createInterfaceType } from './factory.js';
|
|
6
|
+
import { moduleManger } from './modules.js';
|
|
7
|
+
import { isComponentDecorator, isDirectiveDecorator, getInputNames, getInputs, getOutputNames, getOutputs, getTextValueForProperty, isComponentOrDirectiveDecorator, } from './helpers.js';
|
|
8
|
+
/**
|
|
9
|
+
* search for `@Component({})` and precompile the source code
|
|
10
|
+
* @param program a ts program
|
|
11
|
+
* @returns a transformer factory of source file
|
|
12
|
+
*/
|
|
13
|
+
export function beforeCompileComponentOptions(program) {
|
|
14
|
+
const typeChecker = program.getTypeChecker();
|
|
15
|
+
return (context) => {
|
|
16
|
+
return sourceFile => {
|
|
17
|
+
let visitSourceFile = false;
|
|
18
|
+
let componentPropertyName;
|
|
19
|
+
let directivePropertyName;
|
|
20
|
+
for (const statement of sourceFile.statements) {
|
|
21
|
+
if (ts.isImportDeclaration(statement)) {
|
|
22
|
+
const modulePath = statement.moduleSpecifier.getText();
|
|
23
|
+
if (statement.importClause && modulePath.includes('@ibyar/aurora') || modulePath.includes('@ibyar/core')) {
|
|
24
|
+
statement.importClause?.namedBindings?.forEachChild(importSpecifier => {
|
|
25
|
+
if (visitSourceFile) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (ts.isImportSpecifier(importSpecifier)) {
|
|
29
|
+
if (importSpecifier.propertyName?.getText() === 'Component') {
|
|
30
|
+
visitSourceFile = true;
|
|
31
|
+
componentPropertyName = importSpecifier.name.getText();
|
|
32
|
+
}
|
|
33
|
+
else if (importSpecifier.name.getText() === 'Component') {
|
|
34
|
+
visitSourceFile = true;
|
|
35
|
+
componentPropertyName = importSpecifier.name.getText();
|
|
36
|
+
}
|
|
37
|
+
if (importSpecifier.propertyName?.getText() === 'Directive') {
|
|
38
|
+
visitSourceFile = true;
|
|
39
|
+
directivePropertyName = importSpecifier.name.getText();
|
|
40
|
+
}
|
|
41
|
+
else if (importSpecifier.name.getText() === 'Directive') {
|
|
42
|
+
visitSourceFile = true;
|
|
43
|
+
directivePropertyName = importSpecifier.name.getText();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (visitSourceFile) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!visitSourceFile) {
|
|
54
|
+
moduleManger.add({ path: sourceFile.fileName, skip: true });
|
|
55
|
+
return sourceFile;
|
|
56
|
+
}
|
|
57
|
+
const classes = [];
|
|
58
|
+
const updateSourceFile = ts.visitNode(sourceFile, (node) => {
|
|
59
|
+
return ts.visitEachChild(node, (childNode) => {
|
|
60
|
+
let decoratorArguments;
|
|
61
|
+
if (ts.isClassDeclaration(childNode)) {
|
|
62
|
+
const decorators = ts.getDecorators(childNode);
|
|
63
|
+
if (!decorators || decorators.length === 0) {
|
|
64
|
+
return childNode;
|
|
65
|
+
}
|
|
66
|
+
const hasDecorator = decorators.some(decorator => isComponentOrDirectiveDecorator(decorator, componentPropertyName, directivePropertyName));
|
|
67
|
+
if (!hasDecorator) {
|
|
68
|
+
return childNode;
|
|
69
|
+
}
|
|
70
|
+
const viewInfos = [];
|
|
71
|
+
const modifiers = childNode.modifiers?.map(modifier => {
|
|
72
|
+
if (!ts.isDecorator(modifier)) {
|
|
73
|
+
return modifier;
|
|
74
|
+
}
|
|
75
|
+
if (isDirectiveDecorator(modifier)) {
|
|
76
|
+
const options = modifier.expression.arguments[0];
|
|
77
|
+
if (ts.isObjectLiteralExpression(options)) {
|
|
78
|
+
const selector = getTextValueForProperty(options, 'selector');
|
|
79
|
+
if (!selector) {
|
|
80
|
+
return modifier;
|
|
81
|
+
}
|
|
82
|
+
const successor = getTextValueForProperty(options, 'successor');
|
|
83
|
+
const inputs = getInputNames(childNode, typeChecker);
|
|
84
|
+
const outputs = getOutputNames(childNode, typeChecker);
|
|
85
|
+
directiveRegistry.update(selector, { inputs, outputs, successor });
|
|
86
|
+
}
|
|
87
|
+
return modifier;
|
|
88
|
+
}
|
|
89
|
+
if (!isComponentDecorator(modifier)) {
|
|
90
|
+
return modifier;
|
|
91
|
+
}
|
|
92
|
+
const updateDecoratorOptions = (option) => {
|
|
93
|
+
const selector = getTextValueForProperty(option, 'selector');
|
|
94
|
+
if (!selector) {
|
|
95
|
+
console.error(`Component missing selector name: ${childNode.name?.getText()}`);
|
|
96
|
+
return option;
|
|
97
|
+
}
|
|
98
|
+
const viewName = `HTML${selector.split('-')
|
|
99
|
+
.map(name => name.replace(/^\w/, char => char.toUpperCase()))
|
|
100
|
+
.join('')}Element`;
|
|
101
|
+
const extendProperty = option.properties.find(prop => prop.name?.getText() === 'extend');
|
|
102
|
+
const extend = extendProperty?.initializer.getText().substring(1, extendProperty?.initializer.getText().length - 1);
|
|
103
|
+
const extendsType = getExtendsTypeBySelector(extend);
|
|
104
|
+
const formAssociatedProperty = option.properties.find(prop => prop.name?.getText() === 'formAssociated');
|
|
105
|
+
const formAssociated = formAssociatedProperty?.initializer.getText().substring(1, formAssociatedProperty?.initializer.getText().length - 1);
|
|
106
|
+
viewInfos.push({
|
|
107
|
+
selector,
|
|
108
|
+
viewName,
|
|
109
|
+
extendsType,
|
|
110
|
+
interFaceType: createInterfaceType(viewName, extendsType),
|
|
111
|
+
formAssociated: 'true' == formAssociated,
|
|
112
|
+
});
|
|
113
|
+
const stylesProperty = option.properties.find(prop => prop.name?.getText() === 'styles');
|
|
114
|
+
const styles = stylesProperty?.initializer.getText().substring(1, stylesProperty?.initializer.getText().length - 1);
|
|
115
|
+
const template = option.properties.find(prop => prop.name?.getText() === 'template');
|
|
116
|
+
if (template && ts.isPropertyAssignment(template) && ts.isStringLiteralLike(template.initializer)) {
|
|
117
|
+
const text = template?.initializer.getText().substring(1, template?.initializer.getText().length - 1);
|
|
118
|
+
const html = styles
|
|
119
|
+
? `<style>${styles}</style>${text}`
|
|
120
|
+
: text;
|
|
121
|
+
const domNode = htmlParser.toDomRootNode(html);
|
|
122
|
+
buildExpressionNodes(domNode);
|
|
123
|
+
const serialized = JSON.stringify(domNode);
|
|
124
|
+
const json = JSON.parse(serialized);
|
|
125
|
+
const name = ts.factory.createIdentifier('compiledTemplate');
|
|
126
|
+
const initializer = ts.factory.createObjectLiteralExpression(convertToProperties(json));
|
|
127
|
+
const update = ts.factory.updatePropertyAssignment(template, name, initializer);
|
|
128
|
+
decoratorArguments = option.properties.map(prop => {
|
|
129
|
+
if (template === prop) {
|
|
130
|
+
return update;
|
|
131
|
+
}
|
|
132
|
+
return prop;
|
|
133
|
+
}).filter(prop => {
|
|
134
|
+
if (prop.name?.getText(sourceFile) === 'styles') {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
});
|
|
139
|
+
return ts.factory.updateObjectLiteralExpression(option, decoratorArguments);
|
|
140
|
+
}
|
|
141
|
+
return option;
|
|
142
|
+
// options.properties.filter((prop: ts.PropertyAssignment) => {
|
|
143
|
+
// switch (prop.name.getText()) {
|
|
144
|
+
// case 'template':
|
|
145
|
+
// case 'templateUrl':
|
|
146
|
+
// case 'styles':
|
|
147
|
+
// return true;
|
|
148
|
+
// default: return false;
|
|
149
|
+
// }
|
|
150
|
+
// })
|
|
151
|
+
};
|
|
152
|
+
const decoratorCall = modifier.expression;
|
|
153
|
+
const options = decoratorCall.arguments[0];
|
|
154
|
+
let argumentsOption;
|
|
155
|
+
if (ts.isArrayLiteralExpression(options)) {
|
|
156
|
+
const elements = options.elements.map(element => {
|
|
157
|
+
if (ts.isObjectLiteralExpression(element)) {
|
|
158
|
+
return updateDecoratorOptions(element);
|
|
159
|
+
}
|
|
160
|
+
return element;
|
|
161
|
+
});
|
|
162
|
+
argumentsOption = ts.factory.updateArrayLiteralExpression(options, elements);
|
|
163
|
+
}
|
|
164
|
+
else if (ts.isObjectLiteralExpression(options)) {
|
|
165
|
+
argumentsOption = updateDecoratorOptions(options);
|
|
166
|
+
}
|
|
167
|
+
if (argumentsOption) {
|
|
168
|
+
return ts.factory.updateDecorator(modifier, ts.factory.updateCallExpression(decoratorCall, decoratorCall.expression, decoratorCall.typeArguments, [argumentsOption]));
|
|
169
|
+
}
|
|
170
|
+
return modifier;
|
|
171
|
+
});
|
|
172
|
+
classes.push({
|
|
173
|
+
name: childNode.name?.getText() ?? '',
|
|
174
|
+
views: viewInfos,
|
|
175
|
+
inputs: getInputs(childNode, typeChecker),
|
|
176
|
+
outputs: getOutputs(childNode, typeChecker),
|
|
177
|
+
});
|
|
178
|
+
// const staticMembers = viewInfos.map(
|
|
179
|
+
// viewInfo => ts.factory.createPropertyDeclaration(
|
|
180
|
+
// [
|
|
181
|
+
// ts.factory.createModifier(ts.SyntaxKind.StaticKeyword),
|
|
182
|
+
// ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)
|
|
183
|
+
// ],
|
|
184
|
+
// viewInfo.viewName,
|
|
185
|
+
// undefined,
|
|
186
|
+
// createStaticPropertyViewType(viewInfo.viewName),
|
|
187
|
+
// undefined,
|
|
188
|
+
// )
|
|
189
|
+
// );
|
|
190
|
+
return ts.factory.updateClassDeclaration(childNode, modifiers ? ts.factory.createNodeArray(modifiers) : void 0, childNode.name, childNode.typeParameters, childNode.heritageClauses, [/*...staticMembers,*/ ...childNode.members.slice()]);
|
|
191
|
+
}
|
|
192
|
+
return childNode;
|
|
193
|
+
}, context);
|
|
194
|
+
});
|
|
195
|
+
if (classes.length) {
|
|
196
|
+
moduleManger.add({ path: sourceFile.fileName, classes });
|
|
197
|
+
const statements = updateSourceFile.statements?.slice() ?? [];
|
|
198
|
+
statements.push(createConstructorOfViewInterfaceDeclaration());
|
|
199
|
+
const interfaces = classes.flatMap(s => s.views).map(info => {
|
|
200
|
+
return ts.setTextRange(info.interFaceType, updateSourceFile);
|
|
201
|
+
});
|
|
202
|
+
statements.push(); //emit inputs and outputs for component and directives;
|
|
203
|
+
statements.push(...interfaces);
|
|
204
|
+
return ts.factory.updateSourceFile(sourceFile, statements, updateSourceFile.isDeclarationFile, updateSourceFile.typeReferenceDirectives, updateSourceFile.referencedFiles, updateSourceFile.hasNoDefaultLib, updateSourceFile.libReferenceDirectives);
|
|
205
|
+
}
|
|
206
|
+
moduleManger.add({ path: sourceFile.fileName, skip: true });
|
|
207
|
+
return updateSourceFile;
|
|
208
|
+
};
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
export default beforeCompileComponentOptions;
|
|
212
|
+
//# sourceMappingURL=before-component%20copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-component copy.js","sourceRoot":"","sources":["../../../src/cli/transformer/before-component copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EACN,2CAA2C,EAC3C,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAuB,MAAM,cAAc,CAAC;AAC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C,gBAAgB,CAAC,sBAAsB,CACvC,CAAC;YACH,CAAC;YACD,YAAY,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5D,OAAO,gBAAgB,CAAC;QACzB,CAAC,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAED,eAAe,6BAA6B,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { buildExpressionNodes } from '@ibyar/core/node';\nimport { htmlParser, directiveRegistry } from '@ibyar/elements/node';\nimport { getExtendsTypeBySelector } from '../elements/tags.js';\nimport {\n\tcreateConstructorOfViewInterfaceDeclaration,\n\tconvertToProperties, createInterfaceType\n} from './factory.js';\nimport { moduleManger, ViewInfo, ClassInfo } from './modules.js';\nimport {\n\tisComponentDecorator, isDirectiveDecorator,\n\tgetInputNames, getInputs, getOutputNames,\n\tgetOutputs, getTextValueForProperty,\n\tisComponentOrDirectiveDecorator,\n} from './helpers.js';\n\n\n\n/**\n * search for `@Component({})` and precompile the source code\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function beforeCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n\tconst typeChecker = program.getTypeChecker();\n\treturn (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n\t\treturn sourceFile => {\n\t\t\tlet visitSourceFile = false;\n\t\t\tlet componentPropertyName: string;\n\t\t\tlet directivePropertyName: string;\n\t\t\tfor (const statement of sourceFile.statements) {\n\t\t\t\tif (ts.isImportDeclaration(statement)) {\n\t\t\t\t\tconst modulePath = statement.moduleSpecifier.getText();\n\t\t\t\t\tif (statement.importClause && modulePath.includes('@ibyar/aurora') || modulePath.includes('@ibyar/core')) {\n\t\t\t\t\t\tstatement.importClause?.namedBindings?.forEachChild(importSpecifier => {\n\t\t\t\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (ts.isImportSpecifier(importSpecifier)) {\n\t\t\t\t\t\t\t\tif (importSpecifier.propertyName?.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t} else if (importSpecifier.name.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (importSpecifier.propertyName?.getText() === 'Directive') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tdirectivePropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t} else if (importSpecifier.name.getText() === 'Directive') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tdirectivePropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!visitSourceFile) {\n\t\t\t\tmoduleManger.add({ path: sourceFile.fileName, skip: true });\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes: ClassInfo[] = [];\n\t\t\tconst updateSourceFile = ts.visitNode(sourceFile, (node: ts.SourceFile) => {\n\t\t\t\treturn ts.visitEachChild(node, (childNode) => {\n\t\t\t\t\tlet decoratorArguments: ts.ObjectLiteralElementLike[] | undefined;\n\t\t\t\t\tif (ts.isClassDeclaration(childNode)) {\n\t\t\t\t\t\tconst decorators = ts.getDecorators(childNode);\n\t\t\t\t\t\tif (!decorators || decorators.length === 0) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst hasDecorator = decorators.some(decorator => isComponentOrDirectiveDecorator(decorator, componentPropertyName, directivePropertyName));\n\t\t\t\t\t\tif (!hasDecorator) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst viewInfos: ViewInfo[] = [];\n\t\t\t\t\t\tconst modifiers = childNode.modifiers?.map(modifier => {\n\t\t\t\t\t\t\tif (!ts.isDecorator(modifier)) {\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (isDirectiveDecorator(modifier)) {\n\t\t\t\t\t\t\t\tconst options = (modifier.expression as ts.CallExpression).arguments[0];\n\t\t\t\t\t\t\t\tif (ts.isObjectLiteralExpression(options)) {\n\t\t\t\t\t\t\t\t\tconst selector = getTextValueForProperty(options, 'selector');\n\t\t\t\t\t\t\t\t\tif (!selector) {\n\t\t\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst successor = getTextValueForProperty(options, 'successor');\n\t\t\t\t\t\t\t\t\tconst inputs = getInputNames(childNode, typeChecker);\n\t\t\t\t\t\t\t\t\tconst outputs = getOutputNames(childNode, typeChecker);\n\t\t\t\t\t\t\t\t\tdirectiveRegistry.update(selector, { inputs, outputs, successor });\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!isComponentDecorator(modifier)) {\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst updateDecoratorOptions = (option: ts.ObjectLiteralExpression) => {\n\t\t\t\t\t\t\t\tconst selector = getTextValueForProperty(option, 'selector');\n\t\t\t\t\t\t\t\tif (!selector) {\n\t\t\t\t\t\t\t\t\tconsole.error(`Component missing selector name: ${childNode.name?.getText()}`);\n\t\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst viewName = `HTML${selector.split('-')\n\t\t\t\t\t\t\t\t\t.map(name => name.replace(/^\\w/, char => char.toUpperCase()))\n\t\t\t\t\t\t\t\t\t.join('')}Element`;\n\n\n\t\t\t\t\t\t\t\tconst extendProperty = option.properties.find(prop => prop.name?.getText() === 'extend') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst extend = extendProperty?.initializer.getText().substring(1, extendProperty?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\tconst extendsType = getExtendsTypeBySelector(extend);\n\n\t\t\t\t\t\t\t\tconst formAssociatedProperty = option.properties.find(prop => prop.name?.getText() === 'formAssociated') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst formAssociated = formAssociatedProperty?.initializer.getText().substring(1, formAssociatedProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tviewInfos.push({\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\tviewName,\n\t\t\t\t\t\t\t\t\textendsType,\n\t\t\t\t\t\t\t\t\tinterFaceType: createInterfaceType(viewName, extendsType),\n\t\t\t\t\t\t\t\t\tformAssociated: 'true' == formAssociated,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tconst stylesProperty = option.properties.find(prop => prop.name?.getText() === 'styles') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst styles = stylesProperty?.initializer.getText().substring(1, stylesProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tconst template = option.properties.find(prop => prop.name?.getText() === 'template');\n\t\t\t\t\t\t\t\tif (template && ts.isPropertyAssignment(template) && ts.isStringLiteralLike(template.initializer)) {\n\t\t\t\t\t\t\t\t\tconst text = template?.initializer.getText().substring(1, template?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\t\tconst html = styles\n\t\t\t\t\t\t\t\t\t\t? `<style>${styles}</style>${text}`\n\t\t\t\t\t\t\t\t\t\t: text;\n\t\t\t\t\t\t\t\t\tconst domNode = htmlParser.toDomRootNode(html);\n\t\t\t\t\t\t\t\t\tbuildExpressionNodes(domNode);\n\t\t\t\t\t\t\t\t\tconst serialized = JSON.stringify(domNode);\n\t\t\t\t\t\t\t\t\tconst json = JSON.parse(serialized);\n\t\t\t\t\t\t\t\t\tconst name = ts.factory.createIdentifier('compiledTemplate');\n\t\t\t\t\t\t\t\t\tconst initializer = ts.factory.createObjectLiteralExpression(convertToProperties(json));\n\t\t\t\t\t\t\t\t\tconst update = ts.factory.updatePropertyAssignment(template, name, initializer);\n\t\t\t\t\t\t\t\t\tdecoratorArguments = option.properties.map(prop => {\n\t\t\t\t\t\t\t\t\t\tif (template === prop) {\n\t\t\t\t\t\t\t\t\t\t\treturn update;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn prop;\n\t\t\t\t\t\t\t\t\t}).filter(prop => {\n\t\t\t\t\t\t\t\t\t\tif (prop.name?.getText(sourceFile) === 'styles') {\n\t\t\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn ts.factory.updateObjectLiteralExpression(option, decoratorArguments);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn option;\n\n\t\t\t\t\t\t\t\t// options.properties.filter((prop: ts.PropertyAssignment) => {\n\t\t\t\t\t\t\t\t// \tswitch (prop.name.getText()) {\n\t\t\t\t\t\t\t\t// \t\tcase 'template':\n\t\t\t\t\t\t\t\t// \t\tcase 'templateUrl':\n\t\t\t\t\t\t\t\t// \t\tcase 'styles':\n\t\t\t\t\t\t\t\t// \t\t\treturn true;\n\t\t\t\t\t\t\t\t// \t\tdefault: return false;\n\t\t\t\t\t\t\t\t// \t}\n\t\t\t\t\t\t\t\t// })\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tconst decoratorCall = modifier.expression as ts.CallExpression;\n\t\t\t\t\t\t\tconst options = decoratorCall.arguments[0];\n\t\t\t\t\t\t\tlet argumentsOption: ts.Expression | undefined;\n\t\t\t\t\t\t\tif (ts.isArrayLiteralExpression(options)) {\n\t\t\t\t\t\t\t\tconst elements: ts.Expression[] = options.elements.map(element => {\n\t\t\t\t\t\t\t\t\tif (ts.isObjectLiteralExpression(element)) {\n\t\t\t\t\t\t\t\t\t\treturn updateDecoratorOptions(element);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn element;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\targumentsOption = ts.factory.updateArrayLiteralExpression(options, elements);\n\t\t\t\t\t\t\t} else if (ts.isObjectLiteralExpression(options)) {\n\t\t\t\t\t\t\t\targumentsOption = updateDecoratorOptions(options);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (argumentsOption) {\n\t\t\t\t\t\t\t\treturn ts.factory.updateDecorator(\n\t\t\t\t\t\t\t\t\tmodifier,\n\t\t\t\t\t\t\t\t\tts.factory.updateCallExpression(\n\t\t\t\t\t\t\t\t\t\tdecoratorCall,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.expression,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.typeArguments,\n\t\t\t\t\t\t\t\t\t\t[argumentsOption]\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tclasses.push({\n\t\t\t\t\t\t\tname: childNode.name?.getText() ?? '',\n\t\t\t\t\t\t\tviews: viewInfos,\n\t\t\t\t\t\t\tinputs: getInputs(childNode, typeChecker),\n\t\t\t\t\t\t\toutputs: getOutputs(childNode, typeChecker),\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// const staticMembers = viewInfos.map(\n\t\t\t\t\t\t// \tviewInfo => ts.factory.createPropertyDeclaration(\n\t\t\t\t\t\t// \t\t[\n\t\t\t\t\t\t// \t\t\tts.factory.createModifier(ts.SyntaxKind.StaticKeyword),\n\t\t\t\t\t\t// \t\t\tts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)\n\t\t\t\t\t\t// \t\t],\n\t\t\t\t\t\t// \t\tviewInfo.viewName,\n\t\t\t\t\t\t// \t\tundefined,\n\t\t\t\t\t\t// \t\tcreateStaticPropertyViewType(viewInfo.viewName),\n\t\t\t\t\t\t// \t\tundefined,\n\t\t\t\t\t\t// \t)\n\t\t\t\t\t\t// );\n\t\t\t\t\t\treturn ts.factory.updateClassDeclaration(\n\t\t\t\t\t\t\tchildNode,\n\t\t\t\t\t\t\tmodifiers ? ts.factory.createNodeArray(modifiers) : void 0,\n\t\t\t\t\t\t\tchildNode.name,\n\t\t\t\t\t\t\tchildNode.typeParameters,\n\t\t\t\t\t\t\tchildNode.heritageClauses,\n\t\t\t\t\t\t\t[/*...staticMembers,*/ ...childNode.members.slice()],\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn childNode;\n\t\t\t\t}, context);\n\t\t\t}) as ts.SourceFile;\n\t\t\tif (classes.length) {\n\t\t\t\tmoduleManger.add({ path: sourceFile.fileName, classes });\n\t\t\t\tconst statements = updateSourceFile.statements?.slice() ?? [];\n\t\t\t\tstatements.push(createConstructorOfViewInterfaceDeclaration());\n\t\t\t\tconst interfaces = classes.flatMap(s => s.views).map(info => {\n\t\t\t\t\treturn ts.setTextRange(info.interFaceType, updateSourceFile);\n\t\t\t\t});\n\t\t\t\tstatements.push(); //emit inputs and outputs for component and directives;\n\t\t\t\tstatements.push(...interfaces);\n\t\t\t\treturn ts.factory.updateSourceFile(\n\t\t\t\t\tsourceFile,\n\t\t\t\t\tstatements,\n\t\t\t\t\tupdateSourceFile.isDeclarationFile,\n\t\t\t\t\tupdateSourceFile.typeReferenceDirectives,\n\t\t\t\t\tupdateSourceFile.referencedFiles,\n\t\t\t\t\tupdateSourceFile.hasNoDefaultLib,\n\t\t\t\t\tupdateSourceFile.libReferenceDirectives,\n\t\t\t\t);\n\t\t\t}\n\t\t\tmoduleManger.add({ path: sourceFile.fileName, skip: true });\n\t\t\treturn updateSourceFile;\n\t\t};\n\t};\n}\n\nexport default beforeCompileComponentOptions;\n"]}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
-
import { InputOutputTypeInfo } from './modules.js';
|
|
3
2
|
/**
|
|
4
3
|
* search for `@Component({})` and precompile the source code
|
|
5
4
|
* @param program a ts program
|
|
6
5
|
* @returns a transformer factory of source file
|
|
7
6
|
*/
|
|
8
7
|
export declare function beforeCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
|
|
9
|
-
export declare function isInputDecorator(decorator: ts.Decorator): boolean;
|
|
10
|
-
export declare function isOutputDecorator(decorator: ts.Decorator): boolean;
|
|
11
|
-
export declare function getMapByDecorator(classNode: ts.ClassDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): InputOutputTypeInfo;
|
|
12
|
-
export declare function getInputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo;
|
|
13
|
-
export declare function getOutputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo;
|
|
14
|
-
export default beforeCompileComponentOptions;
|
|
15
8
|
//# sourceMappingURL=before-component.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"before-component.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/before-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"before-component.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/before-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAiBnD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAwMvG"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
-
import { buildExpressionNodes } from '@ibyar/core/node';
|
|
3
|
-
import { htmlParser } from '@ibyar/elements/node';
|
|
2
|
+
import { buildExpressionNodes } from '@ibyar/core/node.js';
|
|
3
|
+
import { htmlParser } from '@ibyar/elements/node.js';
|
|
4
4
|
import { getExtendsTypeBySelector } from '../elements/tags.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createConstructorOfViewInterfaceDeclaration, convertToProperties, createInterfaceType } from './factory.js';
|
|
6
6
|
import { moduleManger } from './modules.js';
|
|
7
|
+
import { getInputs, getOutputs, getTextValueForProperty, isComponentDecorator } from './helpers.js';
|
|
7
8
|
/**
|
|
8
9
|
* search for `@Component({})` and precompile the source code
|
|
9
10
|
* @param program a ts program
|
|
@@ -41,7 +42,6 @@ export function beforeCompileComponentOptions(program) {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
if (!visitSourceFile) {
|
|
44
|
-
moduleManger.add({ path: sourceFile.fileName, skip: true });
|
|
45
45
|
return sourceFile;
|
|
46
46
|
}
|
|
47
47
|
const classes = [];
|
|
@@ -53,12 +53,8 @@ export function beforeCompileComponentOptions(program) {
|
|
|
53
53
|
if (!decorators || decorators.length === 0) {
|
|
54
54
|
return childNode;
|
|
55
55
|
}
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
&& decorator.expression.expression.getText() === componentPropertyName;
|
|
59
|
-
};
|
|
60
|
-
const hasComponentDecorator = decorators.some(isComponentDecorator);
|
|
61
|
-
if (!hasComponentDecorator) {
|
|
56
|
+
const hasDecorator = decorators.some(decorator => isComponentDecorator(decorator, componentPropertyName));
|
|
57
|
+
if (!hasDecorator) {
|
|
62
58
|
return childNode;
|
|
63
59
|
}
|
|
64
60
|
const viewInfos = [];
|
|
@@ -66,18 +62,12 @@ export function beforeCompileComponentOptions(program) {
|
|
|
66
62
|
if (!ts.isDecorator(modifier)) {
|
|
67
63
|
return modifier;
|
|
68
64
|
}
|
|
69
|
-
if (!isComponentDecorator(modifier)) {
|
|
70
|
-
return modifier;
|
|
71
|
-
}
|
|
72
65
|
const updateDecoratorOptions = (option) => {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
if (!selectorProperty) {
|
|
66
|
+
const selector = getTextValueForProperty(option, 'selector');
|
|
67
|
+
if (!selector) {
|
|
76
68
|
console.error(`Component missing selector name: ${childNode.name?.getText()}`);
|
|
77
69
|
return option;
|
|
78
70
|
}
|
|
79
|
-
const initializer = selectorProperty.initializer.getText();
|
|
80
|
-
const selector = initializer.substring(1, initializer.length - 1);
|
|
81
71
|
const viewName = `HTML${selector.split('-')
|
|
82
72
|
.map(name => name.replace(/^\w/, char => char.toUpperCase()))
|
|
83
73
|
.join('')}Element`;
|
|
@@ -153,16 +143,25 @@ export function beforeCompileComponentOptions(program) {
|
|
|
153
143
|
return modifier;
|
|
154
144
|
});
|
|
155
145
|
classes.push({
|
|
146
|
+
type: 'component',
|
|
156
147
|
name: childNode.name?.getText() ?? '',
|
|
157
148
|
views: viewInfos,
|
|
158
149
|
inputs: getInputs(childNode, typeChecker),
|
|
159
150
|
outputs: getOutputs(childNode, typeChecker),
|
|
160
151
|
});
|
|
161
|
-
const staticMembers = viewInfos.map(
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
// const staticMembers = viewInfos.map(
|
|
153
|
+
// viewInfo => ts.factory.createPropertyDeclaration(
|
|
154
|
+
// [
|
|
155
|
+
// ts.factory.createModifier(ts.SyntaxKind.StaticKeyword),
|
|
156
|
+
// ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)
|
|
157
|
+
// ],
|
|
158
|
+
// viewInfo.viewName,
|
|
159
|
+
// undefined,
|
|
160
|
+
// createStaticPropertyViewType(viewInfo.viewName),
|
|
161
|
+
// undefined,
|
|
162
|
+
// )
|
|
163
|
+
// );
|
|
164
|
+
return ts.factory.updateClassDeclaration(childNode, modifiers ? ts.factory.createNodeArray(modifiers) : void 0, childNode.name, childNode.typeParameters, childNode.heritageClauses, [/*...staticMembers,*/ ...childNode.members.slice()]);
|
|
166
165
|
}
|
|
167
166
|
return childNode;
|
|
168
167
|
}, context);
|
|
@@ -174,53 +173,12 @@ export function beforeCompileComponentOptions(program) {
|
|
|
174
173
|
const interfaces = classes.flatMap(s => s.views).map(info => {
|
|
175
174
|
return ts.setTextRange(info.interFaceType, updateSourceFile);
|
|
176
175
|
});
|
|
176
|
+
statements.push(); //emit inputs and outputs for component and directives;
|
|
177
177
|
statements.push(...interfaces);
|
|
178
178
|
return ts.factory.updateSourceFile(sourceFile, statements, updateSourceFile.isDeclarationFile, updateSourceFile.typeReferenceDirectives, updateSourceFile.referencedFiles, updateSourceFile.hasNoDefaultLib, updateSourceFile.libReferenceDirectives);
|
|
179
179
|
}
|
|
180
|
-
moduleManger.add({ path: sourceFile.fileName, skip: true });
|
|
181
180
|
return updateSourceFile;
|
|
182
181
|
};
|
|
183
182
|
};
|
|
184
183
|
}
|
|
185
|
-
export function isInputDecorator(decorator) {
|
|
186
|
-
return ts.isCallExpression(decorator.expression) && (decorator.expression.expression.getText() === 'Input'
|
|
187
|
-
|| decorator.expression.expression.getText() === 'FormValue');
|
|
188
|
-
}
|
|
189
|
-
export function isOutputDecorator(decorator) {
|
|
190
|
-
return ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === 'Output';
|
|
191
|
-
}
|
|
192
|
-
export function getMapByDecorator(classNode, checker, decoratorFilter) {
|
|
193
|
-
const map = {};
|
|
194
|
-
classNode.members.forEach(member => {
|
|
195
|
-
if (!ts.isPropertyDeclaration(member)) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
const decorators = ts.getDecorators(member);
|
|
199
|
-
if (!decorators) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const inputDecorators = decorators.filter(decoratorFilter);
|
|
203
|
-
if (!inputDecorators.length) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
let inputType = member.type?.getText();
|
|
207
|
-
if (!inputType && member.initializer) {
|
|
208
|
-
inputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);
|
|
209
|
-
}
|
|
210
|
-
inputDecorators.forEach(input => {
|
|
211
|
-
const decoratorCall = input.expression;
|
|
212
|
-
const aliasName = decoratorCall.arguments[0];
|
|
213
|
-
const inputName = aliasName ? aliasName.text : member.name.getText();
|
|
214
|
-
map[inputName] = inputType;
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
return map;
|
|
218
|
-
}
|
|
219
|
-
export function getInputs(classNode, checker) {
|
|
220
|
-
return getMapByDecorator(classNode, checker, isInputDecorator);
|
|
221
|
-
}
|
|
222
|
-
export function getOutputs(classNode, checker) {
|
|
223
|
-
return getMapByDecorator(classNode, checker, isOutputDecorator);
|
|
224
|
-
}
|
|
225
|
-
export default beforeCompileComponentOptions;
|
|
226
184
|
//# sourceMappingURL=before-component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"before-component.js","sourceRoot":"","sources":["../../../src/cli/transformer/before-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EACN,mBAAmB,EAAE,2CAA2C,EAChE,mBAAmB,EAAE,4BAA4B,EACjD,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAA4C,MAAM,cAAc,CAAC;AAEtF;;;;GAIG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAmB;IAChE,MAA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hF,OAAO,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,SAA8B,EAAE,OAAuB;IACjF,OAAO,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACjE,CAAC;AAED,eAAe,6BAA6B,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { buildExpressionNodes } from '@ibyar/core/node';\nimport { htmlParser } from '@ibyar/elements/node';\nimport { getExtendsTypeBySelector } from '../elements/tags.js';\nimport {\n\tconvertToProperties, createConstructorOfViewInterfaceDeclaration,\n\tcreateInterfaceType, createStaticPropertyViewType\n} from './factory.js';\nimport { moduleManger, ViewInfo, ClassInfo, InputOutputTypeInfo } from './modules.js';\n\n/**\n * search for `@Component({})` and precompile the source code\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function beforeCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n\tconst typeChecker = program.getTypeChecker();\n\treturn (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n\t\treturn sourceFile => {\n\t\t\tlet visitSourceFile = false;\n\t\t\tlet componentPropertyName: string;\n\t\t\tfor (const statement of sourceFile.statements) {\n\t\t\t\tif (ts.isImportDeclaration(statement)) {\n\t\t\t\t\tconst modulePath = statement.moduleSpecifier.getText();\n\t\t\t\t\tif (statement.importClause && modulePath.includes('@ibyar/aurora') || modulePath.includes('@ibyar/core')) {\n\t\t\t\t\t\tstatement.importClause?.namedBindings?.forEachChild(importSpecifier => {\n\t\t\t\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (ts.isImportSpecifier(importSpecifier)) {\n\t\t\t\t\t\t\t\tif (importSpecifier.propertyName?.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t} else if (importSpecifier.name.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!visitSourceFile) {\n\t\t\t\tmoduleManger.add({ path: sourceFile.fileName, skip: true });\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes: ClassInfo[] = [];\n\t\t\tconst updateSourceFile = ts.visitNode(sourceFile, (node: ts.SourceFile) => {\n\t\t\t\treturn ts.visitEachChild(node, (childNode) => {\n\t\t\t\t\tlet decoratorArguments: ts.ObjectLiteralElementLike[] | undefined;\n\t\t\t\t\tif (ts.isClassDeclaration(childNode)) {\n\t\t\t\t\t\tconst decorators = ts.getDecorators(childNode);\n\t\t\t\t\t\tif (!decorators || decorators.length === 0) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst isComponentDecorator = (decorator: ts.Decorator): boolean => {\n\t\t\t\t\t\t\treturn ts.isCallExpression(decorator.expression)\n\t\t\t\t\t\t\t\t&& decorator.expression.expression.getText() === componentPropertyName;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst hasComponentDecorator = decorators.some(isComponentDecorator);\n\t\t\t\t\t\tif (!hasComponentDecorator) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst viewInfos: ViewInfo[] = [];\n\t\t\t\t\t\tconst modifiers = childNode.modifiers?.map(modifier => {\n\t\t\t\t\t\t\tif (!ts.isDecorator(modifier)) {\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!isComponentDecorator(modifier)) {\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst updateDecoratorOptions = (option: ts.ObjectLiteralExpression) => {\n\t\t\t\t\t\t\t\tconst selectorProperty = option.properties\n\t\t\t\t\t\t\t\t\t.find(prop => prop.name?.getText() === 'selector') as ts.PropertyAssignment | undefined;\n\n\t\t\t\t\t\t\t\tif (!selectorProperty) {\n\t\t\t\t\t\t\t\t\tconsole.error(`Component missing selector name: ${childNode.name?.getText()}`);\n\t\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst initializer = selectorProperty.initializer.getText();\n\t\t\t\t\t\t\t\tconst selector = initializer.substring(1, initializer.length - 1);\n\t\t\t\t\t\t\t\tconst viewName = `HTML${selector.split('-')\n\t\t\t\t\t\t\t\t\t.map(name => name.replace(/^\\w/, char => char.toUpperCase()))\n\t\t\t\t\t\t\t\t\t.join('')}Element`;\n\n\n\t\t\t\t\t\t\t\tconst extendProperty = option.properties.find(prop => prop.name?.getText() === 'extend') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst extend = extendProperty?.initializer.getText().substring(1, extendProperty?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\tconst extendsType = getExtendsTypeBySelector(extend);\n\n\t\t\t\t\t\t\t\tconst formAssociatedProperty = option.properties.find(prop => prop.name?.getText() === 'formAssociated') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst formAssociated = formAssociatedProperty?.initializer.getText().substring(1, formAssociatedProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tviewInfos.push({\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\tviewName,\n\t\t\t\t\t\t\t\t\textendsType,\n\t\t\t\t\t\t\t\t\tinterFaceType: createInterfaceType(viewName, extendsType),\n\t\t\t\t\t\t\t\t\tformAssociated: 'true' == formAssociated,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tconst stylesProperty = option.properties.find(prop => prop.name?.getText() === 'styles') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst styles = stylesProperty?.initializer.getText().substring(1, stylesProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tconst template = option.properties.find(prop => prop.name?.getText() === 'template');\n\t\t\t\t\t\t\t\tif (template && ts.isPropertyAssignment(template) && ts.isStringLiteralLike(template.initializer)) {\n\t\t\t\t\t\t\t\t\tconst text = template?.initializer.getText().substring(1, template?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\t\tconst html = styles\n\t\t\t\t\t\t\t\t\t\t? `<style>${styles}</style>${text}`\n\t\t\t\t\t\t\t\t\t\t: text;\n\t\t\t\t\t\t\t\t\tconst domNode = htmlParser.toDomRootNode(html);\n\t\t\t\t\t\t\t\t\tbuildExpressionNodes(domNode);\n\t\t\t\t\t\t\t\t\tconst serialized = JSON.stringify(domNode);\n\t\t\t\t\t\t\t\t\tconst json = JSON.parse(serialized);\n\t\t\t\t\t\t\t\t\tconst name = ts.factory.createIdentifier('compiledTemplate');\n\t\t\t\t\t\t\t\t\tconst initializer = ts.factory.createObjectLiteralExpression(convertToProperties(json));\n\t\t\t\t\t\t\t\t\tconst update = ts.factory.updatePropertyAssignment(template, name, initializer);\n\t\t\t\t\t\t\t\t\tdecoratorArguments = option.properties.map(prop => {\n\t\t\t\t\t\t\t\t\t\tif (template === prop) {\n\t\t\t\t\t\t\t\t\t\t\treturn update;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn prop;\n\t\t\t\t\t\t\t\t\t}).filter(prop => {\n\t\t\t\t\t\t\t\t\t\tif (prop.name?.getText(sourceFile) === 'styles') {\n\t\t\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn ts.factory.updateObjectLiteralExpression(option, decoratorArguments);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn option;\n\n\t\t\t\t\t\t\t\t// options.properties.filter((prop: ts.PropertyAssignment) => {\n\t\t\t\t\t\t\t\t// \tswitch (prop.name.getText()) {\n\t\t\t\t\t\t\t\t// \t\tcase 'template':\n\t\t\t\t\t\t\t\t// \t\tcase 'templateUrl':\n\t\t\t\t\t\t\t\t// \t\tcase 'styles':\n\t\t\t\t\t\t\t\t// \t\t\treturn true;\n\t\t\t\t\t\t\t\t// \t\tdefault: return false;\n\t\t\t\t\t\t\t\t// \t}\n\t\t\t\t\t\t\t\t// })\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tconst decoratorCall = modifier.expression as ts.CallExpression;\n\t\t\t\t\t\t\tconst options = decoratorCall.arguments[0];\n\t\t\t\t\t\t\tlet argumentsOption: ts.Expression | undefined;\n\t\t\t\t\t\t\tif (ts.isArrayLiteralExpression(options)) {\n\t\t\t\t\t\t\t\tconst elements: ts.Expression[] = options.elements.map(element => {\n\t\t\t\t\t\t\t\t\tif (ts.isObjectLiteralExpression(element)) {\n\t\t\t\t\t\t\t\t\t\treturn updateDecoratorOptions(element);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn element;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\targumentsOption = ts.factory.updateArrayLiteralExpression(options, elements);\n\t\t\t\t\t\t\t} else if (ts.isObjectLiteralExpression(options)) {\n\t\t\t\t\t\t\t\targumentsOption = updateDecoratorOptions(options);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (argumentsOption) {\n\t\t\t\t\t\t\t\treturn ts.factory.updateDecorator(\n\t\t\t\t\t\t\t\t\tmodifier,\n\t\t\t\t\t\t\t\t\tts.factory.updateCallExpression(\n\t\t\t\t\t\t\t\t\t\tdecoratorCall,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.expression,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.typeArguments,\n\t\t\t\t\t\t\t\t\t\t[argumentsOption]\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tclasses.push({\n\t\t\t\t\t\t\tname: childNode.name?.getText() ?? '',\n\t\t\t\t\t\t\tviews: viewInfos,\n\t\t\t\t\t\t\tinputs: getInputs(childNode, typeChecker),\n\t\t\t\t\t\t\toutputs: getOutputs(childNode, typeChecker),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst staticMembers = viewInfos.map(\n\t\t\t\t\t\t\tviewInfo => ts.factory.createPropertyDeclaration(\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.StaticKeyword),\n\t\t\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tviewInfo.viewName,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\tcreateStaticPropertyViewType(viewInfo.viewName),\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn ts.factory.updateClassDeclaration(\n\t\t\t\t\t\t\tchildNode,\n\t\t\t\t\t\t\tmodifiers ? ts.factory.createNodeArray(modifiers) : void 0,\n\t\t\t\t\t\t\tchildNode.name,\n\t\t\t\t\t\t\tchildNode.typeParameters,\n\t\t\t\t\t\t\tchildNode.heritageClauses,\n\t\t\t\t\t\t\t[...staticMembers, ...childNode.members.slice()],\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn childNode;\n\t\t\t\t}, context);\n\t\t\t}) as ts.SourceFile;\n\t\t\tif (classes.length) {\n\t\t\t\tmoduleManger.add({ path: sourceFile.fileName, classes });\n\t\t\t\tconst statements = updateSourceFile.statements?.slice() ?? [];\n\t\t\t\tstatements.push(createConstructorOfViewInterfaceDeclaration());\n\t\t\t\tconst interfaces = classes.flatMap(s => s.views).map(info => {\n\t\t\t\t\treturn ts.setTextRange(info.interFaceType, updateSourceFile);\n\t\t\t\t});\n\t\t\t\tstatements.push(...interfaces);\n\t\t\t\treturn ts.factory.updateSourceFile(\n\t\t\t\t\tsourceFile,\n\t\t\t\t\tstatements,\n\t\t\t\t\tupdateSourceFile.isDeclarationFile,\n\t\t\t\t\tupdateSourceFile.typeReferenceDirectives,\n\t\t\t\t\tupdateSourceFile.referencedFiles,\n\t\t\t\t\tupdateSourceFile.hasNoDefaultLib,\n\t\t\t\t\tupdateSourceFile.libReferenceDirectives,\n\t\t\t\t);\n\t\t\t}\n\t\t\tmoduleManger.add({ path: sourceFile.fileName, skip: true });\n\t\t\treturn updateSourceFile;\n\t\t};\n\t};\n}\n\nexport function isInputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && (\n\t\tdecorator.expression.expression.getText() === 'Input'\n\t\t|| decorator.expression.expression.getText() === 'FormValue'\n\t);\n}\n\nexport function isOutputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === 'Output';\n}\n\nexport function getMapByDecorator(classNode: ts.ClassDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): InputOutputTypeInfo {\n\n\tconst map: InputOutputTypeInfo = {};\n\tclassNode.members.forEach(member => {\n\t\tif (!ts.isPropertyDeclaration(member)) {\n\t\t\treturn;\n\t\t}\n\t\tconst decorators = ts.getDecorators(member);\n\t\tif (!decorators) {\n\t\t\treturn;\n\t\t}\n\t\tconst inputDecorators = decorators.filter(decoratorFilter);\n\t\tif (!inputDecorators.length) {\n\t\t\treturn;\n\t\t}\n\t\tlet inputType = member.type?.getText();\n\t\tif (!inputType && member.initializer) {\n\t\t\tinputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);\n\t\t}\n\t\tinputDecorators.forEach(input => {\n\t\t\tconst decoratorCall = input.expression as ts.CallExpression;\n\t\t\tconst aliasName = decoratorCall.arguments[0] as ts.StringLiteralLike;\n\t\t\tconst inputName = aliasName ? aliasName.text : member.name.getText();\n\t\t\tmap[inputName] = inputType;\n\t\t});\n\t})\n\treturn map;\n}\n\nexport function getInputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo {\n\n\treturn getMapByDecorator(classNode, checker, isInputDecorator);\n}\n\nexport function getOutputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): InputOutputTypeInfo {\n\treturn getMapByDecorator(classNode, checker, isOutputDecorator);\n}\n\nexport default beforeCompileComponentOptions;\n"]}
|
|
1
|
+
{"version":3,"file":"before-component.js","sourceRoot":"","sources":["../../../src/cli/transformer/before-component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EACN,2CAA2C,EAC3C,mBAAmB,EAAE,mBAAmB,EACxC,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,YAAY,EAAuB,MAAM,cAAc,CAAC;AACjE,OAAO,EACN,SAAS,EAAE,UAAU,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,MAAM,cAAc,CAAC;AAItB;;;;GAIG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAmB;IAChE,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAC7C,OAAO,CAAC,OAAiC,EAAiC,EAAE;QAC3E,OAAO,UAAU,CAAC,EAAE;YACnB,IAAI,eAAe,GAAG,KAAK,C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AC;YACpB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpB,YAAY,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;gBACzD,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBAC9D,UAAU,CAAC,IAAI,CAAC,2CAA2C,EAAE,CAAC,CAAC;gBAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;oBAC3D,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;gBAC9D,CAAC,CAAC,CAAC;gBACH,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,uDAAuD;gBAC1E,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;gBAC/B,OAAO,EAAE,CAAC,OAAO,CAAC,gBAAgB,CACjC,UAAU,EACV,UAAU,EACV,gBAAgB,CAAC,iBAAiB,EAClC,gBAAgB,CAAC,uBAAuB,EACxC,gBAAgB,CAAC,eAAe,EAChC,gBAAgB,CAAC,eAAe,EAChC,gBAAgB,CAAC,sBAAsB,CACvC,CAAC;YACH,CAAC;YACD,OAAO,gBAAgB,CAAC;QACzB,CAAC,CAAC;IACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { buildExpressionNodes } from '@ibyar/core/node.js';\nimport { htmlParser } from '@ibyar/elements/node.js';\nimport { getExtendsTypeBySelector } from '../elements/tags.js';\nimport {\n\tcreateConstructorOfViewInterfaceDeclaration,\n\tconvertToProperties, createInterfaceType\n} from './factory.js';\nimport { moduleManger, ViewInfo, ClassInfo } from './modules.js';\nimport {\n\tgetInputs, getOutputs,\n\tgetTextValueForProperty,\n\tisComponentDecorator\n} from './helpers.js';\n\n\n\n/**\n * search for `@Component({})` and precompile the source code\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function beforeCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n\tconst typeChecker = program.getTypeChecker();\n\treturn (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n\t\treturn sourceFile => {\n\t\t\tlet visitSourceFile = false;\n\t\t\tlet componentPropertyName: string;\n\t\t\tfor (const statement of sourceFile.statements) {\n\t\t\t\tif (ts.isImportDeclaration(statement)) {\n\t\t\t\t\tconst modulePath = statement.moduleSpecifier.getText();\n\t\t\t\t\tif (statement.importClause && modulePath.includes('@ibyar/aurora') || modulePath.includes('@ibyar/core')) {\n\t\t\t\t\t\tstatement.importClause?.namedBindings?.forEachChild(importSpecifier => {\n\t\t\t\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (ts.isImportSpecifier(importSpecifier)) {\n\t\t\t\t\t\t\t\tif (importSpecifier.propertyName?.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t} else if (importSpecifier.name.getText() === 'Component') {\n\t\t\t\t\t\t\t\t\tvisitSourceFile = true;\n\t\t\t\t\t\t\t\t\tcomponentPropertyName = importSpecifier.name.getText();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (visitSourceFile) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!visitSourceFile) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes: ClassInfo[] = [];\n\t\t\tconst updateSourceFile = ts.visitNode(sourceFile, (node: ts.SourceFile) => {\n\t\t\t\treturn ts.visitEachChild(node, (childNode) => {\n\t\t\t\t\tlet decoratorArguments: ts.ObjectLiteralElementLike[] | undefined;\n\t\t\t\t\tif (ts.isClassDeclaration(childNode)) {\n\t\t\t\t\t\tconst decorators = ts.getDecorators(childNode);\n\t\t\t\t\t\tif (!decorators || decorators.length === 0) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst hasDecorator = decorators.some(decorator => isComponentDecorator(decorator, componentPropertyName));\n\t\t\t\t\t\tif (!hasDecorator) {\n\t\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst viewInfos: ViewInfo[] = [];\n\t\t\t\t\t\tconst modifiers = childNode.modifiers?.map(modifier => {\n\t\t\t\t\t\t\tif (!ts.isDecorator(modifier)) {\n\t\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst updateDecoratorOptions = (option: ts.ObjectLiteralExpression) => {\n\t\t\t\t\t\t\t\tconst selector = getTextValueForProperty(option, 'selector');\n\t\t\t\t\t\t\t\tif (!selector) {\n\t\t\t\t\t\t\t\t\tconsole.error(`Component missing selector name: ${childNode.name?.getText()}`);\n\t\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst viewName = `HTML${selector.split('-')\n\t\t\t\t\t\t\t\t\t.map(name => name.replace(/^\\w/, char => char.toUpperCase()))\n\t\t\t\t\t\t\t\t\t.join('')}Element`;\n\n\n\t\t\t\t\t\t\t\tconst extendProperty = option.properties.find(prop => prop.name?.getText() === 'extend') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst extend = extendProperty?.initializer.getText().substring(1, extendProperty?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\tconst extendsType = getExtendsTypeBySelector(extend);\n\n\t\t\t\t\t\t\t\tconst formAssociatedProperty = option.properties.find(prop => prop.name?.getText() === 'formAssociated') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst formAssociated = formAssociatedProperty?.initializer.getText().substring(1, formAssociatedProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tviewInfos.push({\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\tviewName,\n\t\t\t\t\t\t\t\t\textendsType,\n\t\t\t\t\t\t\t\t\tinterFaceType: createInterfaceType(viewName, extendsType),\n\t\t\t\t\t\t\t\t\tformAssociated: 'true' == formAssociated,\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tconst stylesProperty = option.properties.find(prop => prop.name?.getText() === 'styles') as ts.PropertyAssignment | undefined;\n\t\t\t\t\t\t\t\tconst styles = stylesProperty?.initializer.getText().substring(1, stylesProperty?.initializer.getText().length - 1);\n\n\t\t\t\t\t\t\t\tconst template = option.properties.find(prop => prop.name?.getText() === 'template');\n\t\t\t\t\t\t\t\tif (template && ts.isPropertyAssignment(template) && ts.isStringLiteralLike(template.initializer)) {\n\t\t\t\t\t\t\t\t\tconst text = template?.initializer.getText().substring(1, template?.initializer.getText().length - 1);\n\t\t\t\t\t\t\t\t\tconst html = styles\n\t\t\t\t\t\t\t\t\t\t? `<style>${styles}</style>${text}`\n\t\t\t\t\t\t\t\t\t\t: text;\n\t\t\t\t\t\t\t\t\tconst domNode = htmlParser.toDomRootNode(html);\n\t\t\t\t\t\t\t\t\tbuildExpressionNodes(domNode);\n\t\t\t\t\t\t\t\t\tconst serialized = JSON.stringify(domNode);\n\t\t\t\t\t\t\t\t\tconst json = JSON.parse(serialized);\n\t\t\t\t\t\t\t\t\tconst name = ts.factory.createIdentifier('compiledTemplate');\n\t\t\t\t\t\t\t\t\tconst initializer = ts.factory.createObjectLiteralExpression(convertToProperties(json));\n\t\t\t\t\t\t\t\t\tconst update = ts.factory.updatePropertyAssignment(template, name, initializer);\n\t\t\t\t\t\t\t\t\tdecoratorArguments = option.properties.map(prop => {\n\t\t\t\t\t\t\t\t\t\tif (template === prop) {\n\t\t\t\t\t\t\t\t\t\t\treturn update;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn prop;\n\t\t\t\t\t\t\t\t\t}).filter(prop => {\n\t\t\t\t\t\t\t\t\t\tif (prop.name?.getText(sourceFile) === 'styles') {\n\t\t\t\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\treturn ts.factory.updateObjectLiteralExpression(option, decoratorArguments);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn option;\n\n\t\t\t\t\t\t\t\t// options.properties.filter((prop: ts.PropertyAssignment) => {\n\t\t\t\t\t\t\t\t// \tswitch (prop.name.getText()) {\n\t\t\t\t\t\t\t\t// \t\tcase 'template':\n\t\t\t\t\t\t\t\t// \t\tcase 'templateUrl':\n\t\t\t\t\t\t\t\t// \t\tcase 'styles':\n\t\t\t\t\t\t\t\t// \t\t\treturn true;\n\t\t\t\t\t\t\t\t// \t\tdefault: return false;\n\t\t\t\t\t\t\t\t// \t}\n\t\t\t\t\t\t\t\t// })\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tconst decoratorCall = modifier.expression as ts.CallExpression;\n\t\t\t\t\t\t\tconst options = decoratorCall.arguments[0];\n\t\t\t\t\t\t\tlet argumentsOption: ts.Expression | undefined;\n\t\t\t\t\t\t\tif (ts.isArrayLiteralExpression(options)) {\n\t\t\t\t\t\t\t\tconst elements: ts.Expression[] = options.elements.map(element => {\n\t\t\t\t\t\t\t\t\tif (ts.isObjectLiteralExpression(element)) {\n\t\t\t\t\t\t\t\t\t\treturn updateDecoratorOptions(element);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn element;\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\targumentsOption = ts.factory.updateArrayLiteralExpression(options, elements);\n\t\t\t\t\t\t\t} else if (ts.isObjectLiteralExpression(options)) {\n\t\t\t\t\t\t\t\targumentsOption = updateDecoratorOptions(options);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (argumentsOption) {\n\t\t\t\t\t\t\t\treturn ts.factory.updateDecorator(\n\t\t\t\t\t\t\t\t\tmodifier,\n\t\t\t\t\t\t\t\t\tts.factory.updateCallExpression(\n\t\t\t\t\t\t\t\t\t\tdecoratorCall,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.expression,\n\t\t\t\t\t\t\t\t\t\tdecoratorCall.typeArguments,\n\t\t\t\t\t\t\t\t\t\t[argumentsOption]\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn modifier;\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tclasses.push({\n\t\t\t\t\t\t\ttype: 'component',\n\t\t\t\t\t\t\tname: childNode.name?.getText() ?? '',\n\t\t\t\t\t\t\tviews: viewInfos,\n\t\t\t\t\t\t\tinputs: getInputs(childNode, typeChecker),\n\t\t\t\t\t\t\toutputs: getOutputs(childNode, typeChecker),\n\t\t\t\t\t\t});\n\t\t\t\t\t\t// const staticMembers = viewInfos.map(\n\t\t\t\t\t\t// \tviewInfo => ts.factory.createPropertyDeclaration(\n\t\t\t\t\t\t// \t\t[\n\t\t\t\t\t\t// \t\t\tts.factory.createModifier(ts.SyntaxKind.StaticKeyword),\n\t\t\t\t\t\t// \t\t\tts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)\n\t\t\t\t\t\t// \t\t],\n\t\t\t\t\t\t// \t\tviewInfo.viewName,\n\t\t\t\t\t\t// \t\tundefined,\n\t\t\t\t\t\t// \t\tcreateStaticPropertyViewType(viewInfo.viewName),\n\t\t\t\t\t\t// \t\tundefined,\n\t\t\t\t\t\t// \t)\n\t\t\t\t\t\t// );\n\t\t\t\t\t\treturn ts.factory.updateClassDeclaration(\n\t\t\t\t\t\t\tchildNode,\n\t\t\t\t\t\t\tmodifiers ? ts.factory.createNodeArray(modifiers) : void 0,\n\t\t\t\t\t\t\tchildNode.name,\n\t\t\t\t\t\t\tchildNode.typeParameters,\n\t\t\t\t\t\t\tchildNode.heritageClauses,\n\t\t\t\t\t\t\t[/*...staticMembers,*/ ...childNode.members.slice()],\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn childNode;\n\t\t\t\t}, context);\n\t\t\t}) as ts.SourceFile;\n\t\t\tif (classes.length) {\n\t\t\t\tmoduleManger.add({ path: sourceFile.fileName, classes });\n\t\t\t\tconst statements = updateSourceFile.statements?.slice() ?? [];\n\t\t\t\tstatements.push(createConstructorOfViewInterfaceDeclaration());\n\t\t\t\tconst interfaces = classes.flatMap(s => s.views).map(info => {\n\t\t\t\t\treturn ts.setTextRange(info.interFaceType, updateSourceFile);\n\t\t\t\t});\n\t\t\t\tstatements.push(); //emit inputs and outputs for component and directives;\n\t\t\t\tstatements.push(...interfaces);\n\t\t\t\treturn ts.factory.updateSourceFile(\n\t\t\t\t\tsourceFile,\n\t\t\t\t\tstatements,\n\t\t\t\t\tupdateSourceFile.isDeclarationFile,\n\t\t\t\t\tupdateSourceFile.typeReferenceDirectives,\n\t\t\t\t\tupdateSourceFile.referencedFiles,\n\t\t\t\t\tupdateSourceFile.hasNoDefaultLib,\n\t\t\t\t\tupdateSourceFile.libReferenceDirectives,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn updateSourceFile;\n\t\t};\n\t};\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import ts from 'typescript/lib/tsserverlibrary.js';
|
|
2
|
+
/**
|
|
3
|
+
* search for `@Directive({})` and to register with the html parser
|
|
4
|
+
* @param program a ts program
|
|
5
|
+
* @returns a transformer factory of source file
|
|
6
|
+
*/
|
|
7
|
+
export declare function beforeCompileDirectiveOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
|
|
8
|
+
//# sourceMappingURL=before-directive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"before-directive.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/before-directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAUnD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAkFvG"}
|