@o3r/schematics 8.4.0-alpha.11 → 8.4.0-alpha.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o3r/schematics",
3
- "version": "8.4.0-alpha.11",
3
+ "version": "8.4.0-alpha.13",
4
4
  "description": "Schematics module of the Otter framework",
5
5
  "main": "./src/index.js",
6
6
  "keywords": [
@@ -58,9 +58,9 @@
58
58
  "@nrwl/jest": "~15.9.0",
59
59
  "@nrwl/js": "~15.9.0",
60
60
  "@nrwl/linter": "~15.9.0",
61
- "@o3r/build-helpers": "^8.4.0-alpha.11",
62
- "@o3r/dev-tools": "^8.4.0-alpha.11",
63
- "@o3r/eslint-plugin": "^8.4.0-alpha.11",
61
+ "@o3r/build-helpers": "^8.4.0-alpha.13",
62
+ "@o3r/dev-tools": "^8.4.0-alpha.13",
63
+ "@o3r/eslint-plugin": "^8.4.0-alpha.13",
64
64
  "@schematics/angular": "~15.2.0",
65
65
  "@types/jest": "~28.1.2",
66
66
  "@types/node": "^17.0.45",
@@ -32,4 +32,59 @@ export declare function parseImportsFromFile(sourceFile: ts.SourceFile): {
32
32
  * @param sourcePath
33
33
  */
34
34
  export declare function getExportedSymbolsFromFile(program: ts.Program, sourcePath: string): ts.Symbol[];
35
+ /**
36
+ * Decorator with arguments
37
+ *
38
+ * @example `@Decorator({ propName: 'value' })`
39
+ */
40
+ export type DecoratorWithArg = ts.Decorator & {
41
+ expression: ts.CallExpression & {
42
+ expression: ts.Identifier;
43
+ };
44
+ };
45
+ /**
46
+ * Returns true if it is a decorator with arguments
47
+ *
48
+ * @param node decorator node
49
+ */
50
+ export declare const isDecoratorWithArg: (node: ts.Node) => node is DecoratorWithArg;
51
+ /**
52
+ * Returns the value of {@link argName} in the first argument
53
+ *
54
+ * @param decorator
55
+ * @param argName
56
+ */
57
+ export declare const getPropertyFromDecoratorFirstArgument: (decorator: DecoratorWithArg, argName: string) => ts.Expression | undefined;
58
+ /**
59
+ * Returns `ExpressionWithTypeArguments[]` of a class that implements {@link str}
60
+ *
61
+ * @param str
62
+ */
63
+ export declare const generateImplementsExpressionWithTypeArguments: (str: string) => ts.ExpressionWithTypeArguments[];
64
+ /**
65
+ * Returns `ClassElement[]` of a class that have {@link str} has body
66
+ *
67
+ * @param str
68
+ */
69
+ export declare const generateClassElementsFromString: (str: string) => ts.ClassElement[];
70
+ /**
71
+ * Returns `Statement[]` of a function that have {@link str} has body
72
+ *
73
+ * @param str
74
+ */
75
+ export declare const generateBlockStatementsFromString: (str: string) => ts.Statement[];
76
+ /**
77
+ * Returns `ParameterDeclaration[]` of a function that have {@link str} has parameters
78
+ *
79
+ * @param str
80
+ */
81
+ export declare const generateParametersDeclarationFromString: (str: string) => ts.ParameterDeclaration[];
82
+ /**
83
+ * Method to sort ClassElement based on the kind of it
84
+ * order will be PropertyDeclaration, Constructor then MethodDeclaration
85
+ *
86
+ * @param classElement1
87
+ * @param classElement2
88
+ */
89
+ export declare const sortClassElement: (classElement1: ts.ClassElement, classElement2: ts.ClassElement) => 1 | -1;
35
90
  //# sourceMappingURL=ast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../../src/utility/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,gFAAgF,CAAC;AAGrG;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,GAAG,IAAI,CAa/I;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,UAAU,EA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9B,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC;KAC3B,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,SAAU,OAAO,6BAGA,CAAC;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,qCAAqC,cAAe,gBAAgB,WAAW,MAAM,8BAUjG,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,6CAA6C,QAAS,MAAM,qCAQxE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,QAAS,MAAM,sBAW1D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,QAAS,MAAM,mBAU5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uCAAuC,QAAS,MAAM,8BAQlE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,kBAAmB,GAAG,YAAY,iBAAiB,GAAG,YAAY,WAyB9F,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExportedSymbolsFromFile = exports.parseImportsFromFile = exports.findLastNodeOfKind = exports.findFirstNodeOfKind = void 0;
3
+ exports.sortClassElement = exports.generateParametersDeclarationFromString = exports.generateBlockStatementsFromString = exports.generateClassElementsFromString = exports.generateImplementsExpressionWithTypeArguments = exports.getPropertyFromDecoratorFirstArgument = exports.isDecoratorWithArg = exports.getExportedSymbolsFromFile = exports.parseImportsFromFile = exports.findLastNodeOfKind = exports.findFirstNodeOfKind = void 0;
4
4
  const ts = require("@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript");
5
5
  const ast_utils_1 = require("@schematics/angular/utility/ast-utils");
6
6
  /**
@@ -87,4 +87,106 @@ function getExportedSymbolsFromFile(program, sourcePath) {
87
87
  return typeChecker.getExportsOfModule(symbol);
88
88
  }
89
89
  exports.getExportedSymbolsFromFile = getExportedSymbolsFromFile;
90
+ /**
91
+ * Returns true if it is a decorator with arguments
92
+ *
93
+ * @param node decorator node
94
+ */
95
+ const isDecoratorWithArg = (node) => ts.isDecorator(node)
96
+ && ts.isCallExpression(node.expression)
97
+ && ts.isIdentifier(node.expression.expression);
98
+ exports.isDecoratorWithArg = isDecoratorWithArg;
99
+ /**
100
+ * Returns the value of {@link argName} in the first argument
101
+ *
102
+ * @param decorator
103
+ * @param argName
104
+ */
105
+ const getPropertyFromDecoratorFirstArgument = (decorator, argName) => {
106
+ const ngClassDecoratorArgument = decorator.expression.arguments[0];
107
+ if (ts.isObjectLiteralExpression(ngClassDecoratorArgument)) {
108
+ return ngClassDecoratorArgument.properties.find((prop) => ts.isPropertyAssignment(prop)
109
+ && ts.isIdentifier(prop.name)
110
+ && prop.name.escapedText.toString() === argName)?.initializer;
111
+ }
112
+ };
113
+ exports.getPropertyFromDecoratorFirstArgument = getPropertyFromDecoratorFirstArgument;
114
+ /**
115
+ * Returns `ExpressionWithTypeArguments[]` of a class that implements {@link str}
116
+ *
117
+ * @param str
118
+ */
119
+ const generateImplementsExpressionWithTypeArguments = (str) => {
120
+ const sourceFile = ts.createSourceFile('index.ts', `class A implements ${str} {}`, ts.ScriptTarget.ES2020, true);
121
+ return [...sourceFile.statements[0].heritageClauses[0].types];
122
+ };
123
+ exports.generateImplementsExpressionWithTypeArguments = generateImplementsExpressionWithTypeArguments;
124
+ /**
125
+ * Returns `ClassElement[]` of a class that have {@link str} has body
126
+ *
127
+ * @param str
128
+ */
129
+ const generateClassElementsFromString = (str) => {
130
+ const sourceFile = ts.createSourceFile('index.ts', `class A {
131
+ ${str}
132
+ }`, ts.ScriptTarget.ES2020, true);
133
+ return [...sourceFile.statements[0].members];
134
+ };
135
+ exports.generateClassElementsFromString = generateClassElementsFromString;
136
+ /**
137
+ * Returns `Statement[]` of a function that have {@link str} has body
138
+ *
139
+ * @param str
140
+ */
141
+ const generateBlockStatementsFromString = (str) => {
142
+ const sourceFile = ts.createSourceFile('index.ts', `function func() {
143
+ ${str}
144
+ }`, ts.ScriptTarget.ES2020, true);
145
+ return [...sourceFile.statements[0].body.statements];
146
+ };
147
+ exports.generateBlockStatementsFromString = generateBlockStatementsFromString;
148
+ /**
149
+ * Returns `ParameterDeclaration[]` of a function that have {@link str} has parameters
150
+ *
151
+ * @param str
152
+ */
153
+ const generateParametersDeclarationFromString = (str) => {
154
+ const sourceFile = ts.createSourceFile('index.ts', `function func(${str}) {}`, ts.ScriptTarget.ES2020, true);
155
+ return [...sourceFile.statements[0].parameters];
156
+ };
157
+ exports.generateParametersDeclarationFromString = generateParametersDeclarationFromString;
158
+ /**
159
+ * Method to sort ClassElement based on the kind of it
160
+ * order will be PropertyDeclaration, Constructor then MethodDeclaration
161
+ *
162
+ * @param classElement1
163
+ * @param classElement2
164
+ */
165
+ const sortClassElement = (classElement1, classElement2) => {
166
+ switch (classElement1.kind) {
167
+ case ts.SyntaxKind.PropertyDeclaration: {
168
+ return -1;
169
+ }
170
+ case ts.SyntaxKind.Constructor: {
171
+ switch (classElement2.kind) {
172
+ case ts.SyntaxKind.PropertyDeclaration: {
173
+ return 1;
174
+ }
175
+ case ts.SyntaxKind.MethodDeclaration: {
176
+ return -1;
177
+ }
178
+ default: {
179
+ return -1;
180
+ }
181
+ }
182
+ }
183
+ case ts.SyntaxKind.MethodDeclaration: {
184
+ return 1;
185
+ }
186
+ default: {
187
+ return 1;
188
+ }
189
+ }
190
+ };
191
+ exports.sortClassElement = sortClassElement;
90
192
  //# sourceMappingURL=ast.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../../src/utility/ast.ts"],"names":[],"mappings":";;;AAAA,qGAAqG;AACrG,qEAAkE;AAElE;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAA8B,UAAyB,EAAE,UAAyB,EAAE,IAAc;IACnI,MAAM,WAAW,GAAG,IAAI,IAAI,UAAU,CAAC;IACvC,IAAI,GAAG,GAAa,IAAI,CAAC;IACzB,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE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,mBAAmB,CAAC,CAAC;YACtC,OAAO,CAAC,CAAC,CAAC;SACX;QACD,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YAC9B,QAAQ,aAAa,CAAC,IAAI,EAAE;gBAC1B,KAAK,EAAE,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;oBACtC,OAAO,CAAC,CAAC;iBACV;gBACD,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;oBACpC,OAAO,CAAC,CAAC,CAAC;iBACX;gBACD,OAAO,CAAC,CAAC;oBACP,OAAO,CAAC,CAAC,CAAC;iBACX;aACF;SACF;QACD,KAAK,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;YACpC,OAAO,CAAC,CAAC;SACV;QACD,OAAO,CAAC,CAAC;YACP,OAAO,CAAC,CAAC;SACV;KACF;AACH,CAAC,CAAC;AAzBW,QAAA,gBAAgB,oBAyB3B"}
@@ -0,0 +1,38 @@
1
+ import { Tree } from '@angular-devkit/schematics';
2
+ import * as ts from 'typescript';
3
+ import { DecoratorWithArg } from './ast';
4
+ /**
5
+ * Returns true if `node` is the decorator of an Angular component
6
+ *
7
+ * @param node
8
+ */
9
+ export declare const isNgClassDecorator: (node: ts.Node) => node is DecoratorWithArg;
10
+ /**
11
+ * Returns true if `node` is the decorator of an Otter component
12
+ *
13
+ * @param node
14
+ */
15
+ export declare const isO3rClassDecorator: (node: ts.Node) => node is DecoratorWithArg;
16
+ /**
17
+ * Returns true if `classDeclaration` is an Otter component
18
+ *
19
+ * @param classDeclaration
20
+ */
21
+ export declare const isNgClassComponent: (classDeclaration: ts.ClassDeclaration) => boolean;
22
+ /**
23
+ * Returns true if `classDeclaration` is an Otter component
24
+ *
25
+ * @param classDeclaration
26
+ */
27
+ export declare const isO3rClassComponent: (classDeclaration: ts.ClassDeclaration) => boolean;
28
+ /**
29
+ * Returns Otter component information
30
+ *
31
+ * @param tree
32
+ * @param componentPath
33
+ */
34
+ export declare const getO3rComponentInfo: (tree: Tree, componentPath: string) => {
35
+ name: string;
36
+ selector: string;
37
+ };
38
+ //# sourceMappingURL=component.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../../../src/utility/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAA6D,MAAM,OAAO,CAAC;AAEpG;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,SAAU,OAAO,6BAEsB,CAAC;AAEvE;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,SAAU,OAAO,6BAEwB,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,qBAAsB,GAAG,gBAAgB,YAAwE,CAAC;AAEjJ;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,qBAAsB,GAAG,gBAAgB,YAEA,CAAC;AAE1E;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,SAAU,IAAI,iBAAiB,MAAM;;;CA0CpE,CAAC"}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getO3rComponentInfo = exports.isO3rClassComponent = exports.isNgClassComponent = exports.isO3rClassDecorator = exports.isNgClassDecorator = void 0;
4
+ const ts = require("typescript");
5
+ const ast_1 = require("./ast");
6
+ /**
7
+ * Returns true if `node` is the decorator of an Angular component
8
+ *
9
+ * @param node
10
+ */
11
+ const isNgClassDecorator = (node) => (0, ast_1.isDecoratorWithArg)(node)
12
+ && node.expression.expression.escapedText.toString() === 'Component';
13
+ exports.isNgClassDecorator = isNgClassDecorator;
14
+ /**
15
+ * Returns true if `node` is the decorator of an Otter component
16
+ *
17
+ * @param node
18
+ */
19
+ const isO3rClassDecorator = (node) => (0, ast_1.isDecoratorWithArg)(node)
20
+ && node.expression.expression.escapedText.toString() === 'O3rComponent';
21
+ exports.isO3rClassDecorator = isO3rClassDecorator;
22
+ /**
23
+ * Returns true if `classDeclaration` is an Otter component
24
+ *
25
+ * @param classDeclaration
26
+ */
27
+ const isNgClassComponent = (classDeclaration) => (ts.getDecorators(classDeclaration) || []).some(exports.isNgClassDecorator);
28
+ exports.isNgClassComponent = isNgClassComponent;
29
+ /**
30
+ * Returns true if `classDeclaration` is an Otter component
31
+ *
32
+ * @param classDeclaration
33
+ */
34
+ const isO3rClassComponent = (classDeclaration) => (0, exports.isNgClassComponent)(classDeclaration)
35
+ && (ts.getDecorators(classDeclaration) || []).some(exports.isO3rClassDecorator);
36
+ exports.isO3rClassComponent = isO3rClassComponent;
37
+ /**
38
+ * Returns Otter component information
39
+ *
40
+ * @param tree
41
+ * @param componentPath
42
+ */
43
+ const getO3rComponentInfo = (tree, componentPath) => {
44
+ const sourceFile = ts.createSourceFile(componentPath, tree.readText(componentPath), ts.ScriptTarget.ES2020, true);
45
+ const ngComponentDeclaration = sourceFile.statements.find((s) => ts.isClassDeclaration(s) && (0, exports.isNgClassComponent)(s));
46
+ if (!ngComponentDeclaration) {
47
+ throw new Error(`No Angular component found in ${componentPath}.`);
48
+ }
49
+ if (!(0, exports.isO3rClassComponent)(ngComponentDeclaration)) {
50
+ throw new Error(`No Otter component found in ${componentPath}.`);
51
+ }
52
+ const name = ngComponentDeclaration.name?.escapedText.toString().replace(/Component$/, '');
53
+ if (!name) {
54
+ throw new Error(`The class' name is not specified. Please provide one for the Otter component defined in ${componentPath}.`);
55
+ }
56
+ const selectorExpression = (0, ast_1.getPropertyFromDecoratorFirstArgument)(ts.getDecorators(ngComponentDeclaration)?.find(exports.isNgClassDecorator), 'selector');
57
+ const selector = selectorExpression && ts.isStringLiteral(selectorExpression)
58
+ ? selectorExpression.text
59
+ : selectorExpression?.getText();
60
+ if (!selector) {
61
+ throw new Error(`The component's selector is not specified. Please provide one for the Otter component defined in ${componentPath}.`);
62
+ }
63
+ return {
64
+ name,
65
+ selector
66
+ };
67
+ };
68
+ exports.getO3rComponentInfo = getO3rComponentInfo;
69
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../../../src/utility/component.ts"],"names":[],"mappings":";;;AACA,iCAAiC;AACjC,+BAAoG;AAEpG;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAA4B,EAAE,CAC5E,IAAA,wBAAkB,EAAC,IAAI,CAAC;OACrB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,WAAW,CAAC;AAF1D,QAAA,kBAAkB,sBAEwC;AAEvE;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAa,EAA4B,EAAE,CAC7E,IAAA,wBAAkB,EAAC,IAAI,CAAC;OACrB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,cAAc,CAAC;AAF7D,QAAA,mBAAmB,uBAE0C;AAE1E;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,CAAC,gBAAqC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,0BAAkB,CAAC,CAAC;AAApI,QAAA,kBAAkB,sBAAkH;AAEjJ;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,CAAC,gBAAqC,EAAE,EAAE,CAC3E,IAAA,0BAAkB,EAAC,gBAAgB,CAAC;OACjC,CAAC,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAF7D,QAAA,mBAAmB,uBAE0C;AAE1E;;;;;GAKG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAU,EAAE,aAAqB,EAAE,EAAE;IACvE,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACpC,aAAa,EACb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0C9B"}
@@ -1,4 +1,5 @@
1
1
  export * from './ast';
2
+ export * from './component';
2
3
  export * from './dependencies';
3
4
  export * from './file-info';
4
5
  export * from './generation';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utility/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utility/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./ast"), exports);
5
+ tslib_1.__exportStar(require("./component"), exports);
5
6
  tslib_1.__exportStar(require("./dependencies"), exports);
6
7
  tslib_1.__exportStar(require("./file-info"), exports);
7
8
  tslib_1.__exportStar(require("./generation"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utility/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB;AACtB,yDAA+B;AAC/B,sDAA4B;AAC5B,uDAA6B;AAC7B,sDAA4B;AAC5B,oDAA0B;AAC1B,oDAA0B;AAC1B,mDAAyB;AACzB,sDAA4B;AAC5B,qEAA2C;AAC3C,2DAAiC;AACjC,mEAAyC;AACzC,4DAAkC;AAClC,qDAA2B;AAC3B,2DAAiC;AACjC,uDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utility/index.ts"],"names":[],"mappings":";;;AAAA,gDAAsB;AACtB,sDAA4B;AAC5B,yDAA+B;AAC/B,sDAA4B;AAC5B,uDAA6B;AAC7B,sDAA4B;AAC5B,oDAA0B;AAC1B,oDAA0B;AAC1B,mDAAyB;AACzB,sDAA4B;AAC5B,qEAA2C;AAC3C,2DAAiC;AACjC,mEAAyC;AACzC,4DAAkC;AAClC,qDAA2B;AAC3B,2DAAiC;AACjC,uDAA6B"}