@ibyar/cli 2.2.1 → 2.3.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 CHANGED
@@ -22,11 +22,11 @@ The Ibyar/Aurora CLI tool. ( dev - prerelease)
22
22
  ## `Install`
23
23
 
24
24
  ``` bash
25
- npm i --save @ibyar/cli
25
+ npm i -g --save @ibyar/cli
26
26
  ```
27
27
 
28
28
  ``` bash
29
- yarn add @ibyar/cli
29
+ yarn global add @ibyar/cli
30
30
  ```
31
31
 
32
32
  # How to use
@@ -40,25 +40,26 @@ Usage: ibyar [options]
40
40
 
41
41
  Examples:
42
42
  ibyar
43
- ibyar -b
44
- ibyar -b -w
45
- ibyar -gt
46
- ibyar -v
43
+ ibyar -b # run build
44
+ ibyar -b -w # run build and watch
45
+ ibyar -b -v -w # run build, show tsc logs and watch
46
+ ibyar -v # show cli version
47
47
  ibyar --help
48
48
 
49
49
  Options:
50
50
  -b --build compile the project source code with ibyar transformers
51
51
  and generate '.d.ts' files with created Custom HTML Element definitions.
52
- -w --watch compile and watch source files, used with --build
52
+ -w --watch compile and watch source files, used with --build
53
53
  -h --help print help message
54
54
  -v --version output the version number
55
55
  ```
56
56
 
57
57
 
58
- ## WebPack Bundle
59
58
 
59
+ ## Integration with `Webpack`
60
60
 
61
- - add webpack loader
61
+
62
+ ### add @ibyar/cli as loader
62
63
 
63
64
  ```js
64
65
  module.exports = {
@@ -76,7 +77,50 @@ module.exports = {
76
77
  };
77
78
  ```
78
79
 
79
- ## Rollup Bundle
80
+ ### use `ts-loader`
81
+
82
+ ```js
83
+ // 1. import default from the plugin module
84
+ import {
85
+ beforeCompileDirectiveOptions, beforeCompileComponentOptions,
86
+ afterDeclarationsCompileComponentOptions,
87
+ afterDeclarationsCompileDirectiveOptions,
88
+ scanDirectivesOnceAsTransformer,
89
+ } from '@ibyar/cli';
90
+
91
+
92
+ // 3. add getCustomTransformer method to the loader config
93
+ var config = {
94
+ ...
95
+ module: {
96
+ rules: [
97
+ {
98
+ test: /\.tsx?$/,
99
+ loader: 'ts-loader',
100
+ options: {
101
+ ... // other loader's options
102
+ getCustomTransformers: () => ({
103
+ before: [
104
+ scanDirectivesOnceAsTransformer(),
105
+ beforeCompileDirectiveOptions,
106
+ beforeCompileComponentOptions,
107
+ ],
108
+ after: [],
109
+ afterDeclarations: [
110
+ afterDeclarationsCompileComponentOptions,
111
+ afterDeclarationsCompileDirectiveOptions,
112
+ ],
113
+ })
114
+ }
115
+ }
116
+ ]
117
+ }
118
+ ...
119
+ };
120
+ ```
121
+
122
+ ## Integration with `Rollup`
123
+
80
124
 
81
125
  ```js
82
126
  import typescript from '@rollup/plugin-typescript';
@@ -90,7 +134,6 @@ import {
90
134
  export default = {
91
135
  ...,
92
136
  plugins: [
93
- nodeResolve(),
94
137
  typescript({
95
138
  transformers: {
96
139
  before: [
@@ -105,14 +148,13 @@ export default = {
105
148
  ],
106
149
  }
107
150
  }),
108
- html({ include: "**/*.html" }),
109
- css({ output: 'style.css' }),
110
151
  ],
111
152
  };
112
153
 
113
154
  ```
114
155
 
115
156
 
157
+
116
158
  The Ibyar CLI has a typescript transformer to generate a definitions for you component
117
159
 
118
160
  ```ts
@@ -6,6 +6,10 @@ export declare function scanDirectivesOnceAsTransformer(): (program: ts.Program)
6
6
  export declare function emitProgram(program: ts.Program): void;
7
7
  export declare function compileFiles(files: readonly string[], options: ts.CompilerOptions): void;
8
8
  export declare function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine): void;
9
+ export declare function patchProgram(tsProgram: ts.Program): void;
10
+ export declare function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames: readonly string[] | undefined, options: ts.CompilerOptions | undefined, host?: ts.CompilerHost, oldProgram?: ts.EmitAndSemanticDiagnosticsBuilderProgram | undefined, configFileParsingDiagnostics?: readonly ts.Diagnostic[], projectReferences?: readonly ts.ProjectReference[] | undefined): ts.EmitAndSemanticDiagnosticsBuilderProgram;
11
+ export declare function compileSolution(configFilePath: string, cmd: ts.ParsedCommandLine): void;
12
+ export declare function compileSolutionAndWatch(configFilePath: string, cmd: ts.ParsedCommandLine): void;
9
13
  export declare function getConfigPath(): string;
10
14
  export declare function compileArgs(): void;
11
15
  export declare function compileAndWatchArgs(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAOnD,wBAAgB,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAY1E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAEjD;AAED,wBAAgB,+BAA+B,cAG7B,EAAE,CAAC,OAAO,eADO,EAAE,CAAC,qBAAqB,KAAG,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,CAS1F;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAG9C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,QAIjF;AAoBD,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,QAejF;AAID,wBAAgB,aAAa,WAW5B;AAED,wBAAgB,WAAW,SAO1B;AAED,wBAAgB,mBAAmB,SAOlC"}
1
+ {"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AASnD,wBAAgB,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAY1E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAEjD;AAED,wBAAgB,+BAA+B,cAG7B,EAAE,CAAC,OAAO,eADO,EAAE,CAAC,qBAAqB,KAAG,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,UAAU,CAAC,CAS1F;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAG9C;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,QAIjF;AAoBD,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,QAejF;AAID,wBAAgB,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,QAcjD;AAED,wBAAgB,8CAA8C,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC,eAAe,GAAG,SAAS,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,EAAE,CAAC,wCAAwC,GAAG,SAAS,EAAE,4BAA4B,CAAC,EAAE,SAAS,EAAE,CAAC,UAAU,EAAE,EAAE,iBAAiB,CAAC,EAAE,SAAS,EAAE,CAAC,gBAAgB,EAAE,GAAG,SAAS,+CAKtW;AA4BD,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,QAKhF;AAED,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,iBAAiB,QAKxF;AAED,wBAAgB,aAAa,WAkB5B;AAED,wBAAgB,WAAW,SAW1B;AAED,wBAAgB,mBAAmB,SAWlC"}
@@ -5,6 +5,8 @@ import { afterDeclarationsCompileDirectiveOptions } from '../transformer/after-d
5
5
  import { beforeCompileComponentOptions } from '../transformer/before-component.js';
6
6
  import { beforeCompileDirectiveOptions } from '../transformer/before-directive.js';
7
7
  import { scanDirectivesTypeVisitor } from '../transformer/scan-directives.js';
8
+ import { dirname, join, resolve } from 'path';
9
+ import { existsSync } from 'fs';
8
10
  export function getTransformers(program) {
9
11
  return {
10
12
  before: [
@@ -65,8 +67,70 @@ export function compileAndWatchFiles(configPath, cmd) {
65
67
  const program = programBuilder.getProgram();
66
68
  emitProgram(program);
67
69
  }
70
+ export function patchProgram(tsProgram) {
71
+ const program = tsProgram;
72
+ program.__emit = program.emit;
73
+ const programTransformers = getTransformers(program);
74
+ program.emit = (targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
75
+ if (!customTransformers) {
76
+ return program.__emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, programTransformers);
77
+ }
78
+ return program.__emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, {
79
+ before: [...(customTransformers?.before ?? []), ...programTransformers.before],
80
+ after: [...(customTransformers?.after ?? []), ...programTransformers.after],
81
+ afterDeclarations: [...(customTransformers?.afterDeclarations ?? []), ...programTransformers.afterDeclarations],
82
+ });
83
+ };
84
+ }
85
+ export function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences) {
86
+ const program = ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences);
87
+ scanDirectives(program.getProgram());
88
+ patchProgram(program.getProgram());
89
+ return program;
90
+ }
91
+ const diagHost = {
92
+ getCanonicalFileName: function (fileName) {
93
+ return ts.sys.resolvePath(fileName);
94
+ },
95
+ getCurrentDirectory: function () {
96
+ return ts.sys.getCurrentDirectory();
97
+ },
98
+ getNewLine: function () {
99
+ return ts.sys.newLine;
100
+ }
101
+ };
102
+ function reportDiag(diag) {
103
+ let output = ts.sys.writeOutputIsTTY && ts.sys.writeOutputIsTTY() ?
104
+ ts.formatDiagnosticsWithColorAndContext([diag], diagHost) :
105
+ ts.formatDiagnostic(diag, diagHost);
106
+ output = output.replace(/^[\r\n]+/, '').replace(/[\r\n]+$/, '');
107
+ ts.sys.write(output + '\n');
108
+ }
109
+ function reportError(errorCount, filesInError) {
110
+ ts.sys.write(`Error count: ${errorCount}\n`);
111
+ filesInError.forEach(error => ts.sys.write(`Error file: ${error?.fileName}(${error?.line})\n`));
112
+ }
113
+ export function compileSolution(configFilePath, cmd) {
114
+ const rootNames = [dirname(configFilePath)];
115
+ const solutionHost = ts.createSolutionBuilderHost(ts.sys, createEmitAndSemanticDiagnosticsBuilderProgram, reportDiag, reportDiag, reportError);
116
+ const solution = ts.createSolutionBuilder(solutionHost, rootNames, {});
117
+ solution.build();
118
+ }
119
+ export function compileSolutionAndWatch(configFilePath, cmd) {
120
+ const rootNames = [dirname(configFilePath)];
121
+ const solutionHost = ts.createSolutionBuilderWithWatchHost(ts.sys, createEmitAndSemanticDiagnosticsBuilderProgram, reportDiag, reportDiag, reportDiag);
122
+ const solution = ts.createSolutionBuilderWithWatch(solutionHost, rootNames, {}, cmd.watchOptions);
123
+ solution.build();
124
+ }
68
125
  export function getConfigPath() {
69
- const tsconfig = process.argv.slice(2).filter(arg => arg.includes('tsconfig'))[0];
126
+ const args = process.argv.slice(2);
127
+ let tsconfig = args.filter(arg => arg.includes('tsconfig'))[0];
128
+ if (!tsconfig && args.length > 1 /** -b */) {
129
+ const path = join(args.at(-1), 'tsconfig.json');
130
+ if (existsSync(path)) {
131
+ tsconfig = resolve(path);
132
+ }
133
+ }
70
134
  const configPath = ts.findConfigFile('./', /*searchPath*/ ts.sys.fileExists, tsconfig ?? 'tsconfig.json');
71
135
  if (!configPath) {
72
136
  throw new Error("Could not find a valid 'tsconfig.json'.");
@@ -79,7 +143,12 @@ export function compileArgs() {
79
143
  if (!cmd) {
80
144
  return;
81
145
  }
82
- compileFiles(cmd.fileNames, cmd.options);
146
+ if (cmd.projectReferences?.length) {
147
+ compileSolution(configPath, cmd);
148
+ }
149
+ else {
150
+ compileFiles(cmd.fileNames, cmd.options);
151
+ }
83
152
  }
84
153
  export function compileAndWatchArgs() {
85
154
  const configPath = getConfigPath();
@@ -87,6 +156,11 @@ export function compileAndWatchArgs() {
87
156
  if (!cmd) {
88
157
  return;
89
158
  }
90
- compileAndWatchFiles(configPath, cmd);
159
+ if (cmd.projectReferences?.length) {
160
+ compileSolutionAndWatch(configPath, cmd);
161
+ }
162
+ else {
163
+ compileAndWatchFiles(configPath, cmd);
164
+ }
91
165
  }
92
166
  //# sourceMappingURL=compiler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAE9E,MAAM,UAAU,eAAe,CAAC,OAAmB;IAClD,OAAO;QACN,MAAM,EAAE;YACP,6BAA6B,CAAC,OAAO,CAAC;YACtC,6BAA6B,CAAC,OAAO,CAAC;SACtC;QACD,KAAK,EAAE,EAAE;QACT,iBAAiB,EAAE;YAClB,wCAAwC,CAAC,OAAO,CAAqD;YACrG,wCAAwC,CAAC,OAAO,CAAqD;SACrG;KACD,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAmB;IACjD,OAAO,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,+BAA+B;IAC9C,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,IAAI,iBAAiB,GAAG,CAAC,OAAiC,EA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AAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO;IACR,CAAC;IACD,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,mBAAmB;IAClC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,gCAAgC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,GAAU,CAAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO;IACR,CAAC;IACD,oBAAoB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import '../directives/register.js';\nimport ts from 'typescript/lib/tsserverlibrary.js';\nimport { afterDeclarationsCompileComponentOptions } from '../transformer/after-declarations-component.js';\nimport { afterDeclarationsCompileDirectiveOptions } from '../transformer/after-declarations-directive.js';\nimport { beforeCompileComponentOptions } from '../transformer/before-component.js';\nimport { beforeCompileDirectiveOptions } from '../transformer/before-directive.js';\nimport { scanDirectivesTypeVisitor } from '../transformer/scan-directives.js';\n\nexport function getTransformers(program: ts.Program): ts.CustomTransformers {\n\treturn {\n\t\tbefore: [\n\t\t\tbeforeCompileDirectiveOptions(program),\n\t\t\tbeforeCompileComponentOptions(program),\n\t\t],\n\t\tafter: [],\n\t\tafterDeclarations: [\n\t\t\tafterDeclarationsCompileComponentOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t\tafterDeclarationsCompileDirectiveOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t],\n\t};\n}\n\nexport function scanDirectives(program: ts.Program) {\n\tprogram.getSourceFiles().forEach(scanDirectivesTypeVisitor);\n}\n\nexport function scanDirectivesOnceAsTransformer() {\n\tlet scanDone = false;\n\tlet ignoreTransformer = (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => sourceFile => sourceFile;\n\treturn (program: ts.Program) => {\n\t\tif (scanDone) {\n\t\t\treturn ignoreTransformer;\n\t\t}\n\t\tscanDone = true;\n\t\tscanDirectives(program);\n\t\treturn ignoreTransformer;\n\t};\n}\n\nexport function emitProgram(program: ts.Program) {\n\tscanDirectives(program);\n\tprogram.emit(undefined, undefined, undefined, undefined, getTransformers(program));\n}\n\nexport function compileFiles(files: readonly string[], options: ts.CompilerOptions) {\n\tconst host = ts.createCompilerHost(options);\n\tconst program = ts.createProgram(files, options, host);\n\temitProgram(program);\n}\n\nconst formatHost: ts.FormatDiagnosticsHost = {\n\tgetCanonicalFileName: path => path,\n\tgetCurrentDirectory: ts.sys.getCurrentDirectory,\n\tgetNewLine: () => ts.sys.newLine\n};\n\nfunction reportDiagnostic(diagnostic: ts.Diagnostic) {\n\tconsole.error(\"Error\", diagnostic.code, \":\", ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));\n}\n\n/**\n * Prints a diagnostic every time the watch status changes.\n * This is mainly for messages like \"Starting compilation\" or \"Compilation completed\".\n */\nfunction reportWatchStatusChanged(diagnostic: ts.Diagnostic) {\n\tconsole.info(ts.formatDiagnostic(diagnostic, formatHost));\n}\n\nexport function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine) {\n\tconst createProgram = ts.createSemanticDiagnosticsBuilderProgram;\n\tconst host = ts.createWatchCompilerHost(\n\t\tconfigPath,\n\t\tcmd.options,\n\t\tts.sys,\n\t\tcreateProgram,\n\t\treportDiagnostic,\n\t\treportWatchStatusChanged,\n\t\tcmd.watchOptions,\n\t);\n\tconst programFactory = ts.createWatchProgram(host);\n\tconst programBuilder = programFactory.getProgram();\n\tconst program = programBuilder.getProgram();\n\temitProgram(program);\n}\n\n\n\nexport function getConfigPath() {\n\tconst tsconfig = process.argv.slice(2).filter(arg => arg.includes('tsconfig'))[0];\n\tconst configPath = ts.findConfigFile(\n\t\t'./',\t\t\t/*searchPath*/\n\t\tts.sys.fileExists,\n\t\ttsconfig ?? 'tsconfig.json'\n\t);\n\tif (!configPath) {\n\t\tthrow new Error(\"Could not find a valid 'tsconfig.json'.\");\n\t}\n\treturn configPath;\n}\n\nexport function compileArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileFiles(cmd.fileNames, cmd.options);\n}\n\nexport function compileAndWatchArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tcompileAndWatchFiles(configPath, cmd);\n}\n"]}
1
+ {"version":3,"file":"compiler.js","sourceRoot":"","sources":["../../../src/cli/compiler/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,wCAAwC,EAAE,MAAM,gDAAgD,CAAC;AAC1G,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,MAAM,UAAU,eAAe,CAAC,OAAmB;IAClD,OAAO;QACN,MAAM,EAAE;YACP,6BAA6B,CAAC,OAAO,CAAC;YACtC,6BAA6B,CAAC,OAAO,CAAC;SACtC;QACD,KAAK,EAAE,EAAE;QACT,iBAAiB,EAAE;YAClB,wCAAwC,CAAC,OAAO,CAAqD;YACrG,wCAAwC,CAAC,OAAO,CAAqD;SACrG;KACD,CAAC;AACH,CAAC;AA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U,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,gCAAgC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,GAAU,CAAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO;IACR,CAAC;IACD,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAC;QACnC,eAAe,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACP,YAAY,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;AACF,CAAC;AAED,MAAM,UAAU,mBAAmB;IAClC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,gCAAgC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,CAAC,GAAU,CAAC,CAAC;IAC/E,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,OAAO;IACR,CAAC;IACD,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,EAAE,CAAC;QACnC,uBAAuB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAC1C,CAAC;SAAM,CAAC;QACP,oBAAoB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;AACF,CAAC","sourcesContent":["import '../directives/register.js';\nimport ts from 'typescript/lib/tsserverlibrary.js';\nimport { afterDeclarationsCompileComponentOptions } from '../transformer/after-declarations-component.js';\nimport { afterDeclarationsCompileDirectiveOptions } from '../transformer/after-declarations-directive.js';\nimport { beforeCompileComponentOptions } from '../transformer/before-component.js';\nimport { beforeCompileDirectiveOptions } from '../transformer/before-directive.js';\nimport { scanDirectivesTypeVisitor } from '../transformer/scan-directives.js';\nimport { dirname, join, resolve } from 'path';\nimport { existsSync } from 'fs';\n\nexport function getTransformers(program: ts.Program): ts.CustomTransformers {\n\treturn {\n\t\tbefore: [\n\t\t\tbeforeCompileDirectiveOptions(program),\n\t\t\tbeforeCompileComponentOptions(program),\n\t\t],\n\t\tafter: [],\n\t\tafterDeclarations: [\n\t\t\tafterDeclarationsCompileComponentOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t\tafterDeclarationsCompileDirectiveOptions(program) as ts.TransformerFactory<ts.SourceFile | ts.Bundle>,\n\t\t],\n\t};\n}\n\nexport function scanDirectives(program: ts.Program) {\n\tprogram.getSourceFiles().forEach(scanDirectivesTypeVisitor);\n}\n\nexport function scanDirectivesOnceAsTransformer() {\n\tlet scanDone = false;\n\tlet ignoreTransformer = (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => sourceFile => sourceFile;\n\treturn (program: ts.Program) => {\n\t\tif (scanDone) {\n\t\t\treturn ignoreTransformer;\n\t\t}\n\t\tscanDone = true;\n\t\tscanDirectives(program);\n\t\treturn ignoreTransformer;\n\t};\n}\n\nexport function emitProgram(program: ts.Program) {\n\tscanDirectives(program);\n\tprogram.emit(undefined, undefined, undefined, undefined, getTransformers(program));\n}\n\nexport function compileFiles(files: readonly string[], options: ts.CompilerOptions) {\n\tconst host = ts.createCompilerHost(options);\n\tconst program = ts.createProgram(files, options, host);\n\temitProgram(program);\n}\n\nconst formatHost: ts.FormatDiagnosticsHost = {\n\tgetCanonicalFileName: path => path,\n\tgetCurrentDirectory: ts.sys.getCurrentDirectory,\n\tgetNewLine: () => ts.sys.newLine\n};\n\nfunction reportDiagnostic(diagnostic: ts.Diagnostic) {\n\tconsole.error(\"Error\", diagnostic.code, \":\", ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine()));\n}\n\n/**\n * Prints a diagnostic every time the watch status changes.\n * This is mainly for messages like \"Starting compilation\" or \"Compilation completed\".\n */\nfunction reportWatchStatusChanged(diagnostic: ts.Diagnostic) {\n\tconsole.info(ts.formatDiagnostic(diagnostic, formatHost));\n}\n\nexport function compileAndWatchFiles(configPath: string, cmd: ts.ParsedCommandLine) {\n\tconst createProgram = ts.createSemanticDiagnosticsBuilderProgram;\n\tconst host = ts.createWatchCompilerHost(\n\t\tconfigPath,\n\t\tcmd.options,\n\t\tts.sys,\n\t\tcreateProgram,\n\t\treportDiagnostic,\n\t\treportWatchStatusChanged,\n\t\tcmd.watchOptions,\n\t);\n\tconst programFactory = ts.createWatchProgram(host);\n\tconst programBuilder = programFactory.getProgram();\n\tconst program = programBuilder.getProgram();\n\temitProgram(program);\n}\n\ntype ProgramPatch = ts.Program & { __emit: (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback, cancellationToken?: ts.CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: ts.CustomTransformers) => ts.EmitResult };\n\nexport function patchProgram(tsProgram: ts.Program) {\n\tconst program = tsProgram as ProgramPatch;\n\tprogram.__emit = program.emit;\n\tconst programTransformers = getTransformers(program);\n\tprogram.emit = (targetSourceFile?: ts.SourceFile, writeFile?: ts.WriteFileCallback, cancellationToken?: ts.CancellationToken, emitOnlyDtsFiles?: boolean, customTransformers?: ts.CustomTransformers): ts.EmitResult => {\n\t\tif (!customTransformers) {\n\t\t\treturn program.__emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, programTransformers);\n\t\t}\n\t\treturn program.__emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, {\n\t\t\tbefore: [...(customTransformers?.before ?? []), ...programTransformers.before!],\n\t\t\tafter: [...(customTransformers?.after ?? []), ...programTransformers.after!],\n\t\t\tafterDeclarations: [...(customTransformers?.afterDeclarations ?? []), ...programTransformers.afterDeclarations!],\n\t\t});\n\t};\n}\n\nexport function createEmitAndSemanticDiagnosticsBuilderProgram(rootNames: readonly string[] | undefined, options: ts.CompilerOptions | undefined, host?: ts.CompilerHost, oldProgram?: ts.EmitAndSemanticDiagnosticsBuilderProgram | undefined, configFileParsingDiagnostics?: readonly ts.Diagnostic[], projectReferences?: readonly ts.ProjectReference[] | undefined) {\n\tconst program = ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences);\n\tscanDirectives(program.getProgram());\n\tpatchProgram(program.getProgram());\n\treturn program;\n}\n\n\nconst diagHost = {\n\tgetCanonicalFileName: function (fileName: string) {\n\t\treturn ts.sys.resolvePath(fileName)\n\t},\n\tgetCurrentDirectory: function () {\n\t\treturn ts.sys.getCurrentDirectory();\n\t},\n\tgetNewLine: function () {\n\t\treturn ts.sys.newLine;\n\t}\n};\n\nfunction reportDiag(diag: ts.Diagnostic) {\n\tlet output = ts.sys.writeOutputIsTTY && ts.sys.writeOutputIsTTY() ?\n\t\tts.formatDiagnosticsWithColorAndContext([diag], diagHost) :\n\t\tts.formatDiagnostic(diag, diagHost);\n\toutput = output.replace(/^[\\r\\n]+/, '').replace(/[\\r\\n]+$/, '');\n\tts.sys.write(output + '\\n');\n}\n\nfunction reportError(errorCount: number, filesInError: (ts.ReportFileInError | undefined)[]) {\n\tts.sys.write(`Error count: ${errorCount}\\n`);\n\tfilesInError.forEach(error => ts.sys.write(`Error file: ${error?.fileName}(${error?.line})\\n`));\n}\n\nexport function compileSolution(configFilePath: string, cmd: ts.ParsedCommandLine) {\n\tconst rootNames = [dirname(configFilePath)];\n\tconst solutionHost = ts.createSolutionBuilderHost(ts.sys, createEmitAndSemanticDiagnosticsBuilderProgram, reportDiag, reportDiag, reportError);\n\tconst solution = ts.createSolutionBuilder(solutionHost, rootNames, {});\n\tsolution.build();\n}\n\nexport function compileSolutionAndWatch(configFilePath: string, cmd: ts.ParsedCommandLine) {\n\tconst rootNames = [dirname(configFilePath)];\n\tconst solutionHost = ts.createSolutionBuilderWithWatchHost(ts.sys, createEmitAndSemanticDiagnosticsBuilderProgram, reportDiag, reportDiag, reportDiag);\n\tconst solution = ts.createSolutionBuilderWithWatch(solutionHost, rootNames, {}, cmd.watchOptions);\n\tsolution.build();\n}\n\nexport function getConfigPath() {\n\tconst args = process.argv.slice(2);\n\tlet tsconfig = args.filter(arg => arg.includes('tsconfig'))[0];\n\tif (!tsconfig && args.length > 1 /** -b */) {\n\t\tconst path = join(args.at(-1)!, 'tsconfig.json');\n\t\tif (existsSync(path)) {\n\t\t\ttsconfig = resolve(path);\n\t\t}\n\t}\n\tconst configPath = ts.findConfigFile(\n\t\t'./',\t\t\t/*searchPath*/\n\t\tts.sys.fileExists,\n\t\ttsconfig ?? 'tsconfig.json'\n\t);\n\tif (!configPath) {\n\t\tthrow new Error(\"Could not find a valid 'tsconfig.json'.\");\n\t}\n\treturn configPath;\n}\n\nexport function compileArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tif (cmd.projectReferences?.length) {\n\t\tcompileSolution(configPath, cmd);\n\t} else {\n\t\tcompileFiles(cmd.fileNames, cmd.options);\n\t}\n}\n\nexport function compileAndWatchArgs() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\treturn;\n\t}\n\tif (cmd.projectReferences?.length) {\n\t\tcompileSolutionAndWatch(configPath, cmd);\n\t} else {\n\t\tcompileAndWatchFiles(configPath, cmd);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/cli/directives/register.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,MAAM,WAAW,aAAa;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1B;AACD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,QAcxD"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../src/cli/directives/register.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,MAAM,WAAW,aAAa;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,aAAa,QAgBxD"}
@@ -1,12 +1,13 @@
1
- import { registerDirective } from '@ibyar/core/node.js';
1
+ import { deleteDirective, provideDirective } from '@ibyar/core/node.js';
2
2
  import { directiveRegistry } from '@ibyar/elements/node.js';
3
3
  import { metadataHoler } from '@ibyar/decorators';
4
4
  export function registerDirectiveCall(info) {
5
- directiveRegistry.register(info.selector, {
5
+ directiveRegistry.set(info.selector, {
6
6
  successor: info.successor,
7
7
  inputs: info.inputs?.map(i => i.aliasName),
8
8
  outputs: info.outputs?.map(i => i.aliasName),
9
9
  });
10
+ deleteDirective(info.selector);
10
11
  const modelClass = {};
11
12
  const modelKey = {};
12
13
  modelClass[Symbol.metadata] = modelKey;
@@ -14,6 +15,6 @@ export function registerDirectiveCall(info) {
14
15
  metadata.modelClass = modelClass;
15
16
  metadata.selector = info.selector;
16
17
  metadata.inputs = info.inputs?.map(input => ({ modelProperty: input.name, viewAttribute: input.aliasName }));
17
- registerDirective(modelClass);
18
+ provideDirective(modelClass);
18
19
  }
19
20
  //# sourceMappingURL=register.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.js","sourceRoot":"","sources":["../../../src/cli/directives/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAQlD,MAAM,UAAU,qBAAqB,CAAC,IAAmB;IACxD,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE;QACzC,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1C,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;KAC5C,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,QAAQ,GAAG,EAAE,CAAC;IACnB,UAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IAChD,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrD,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAClC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC7G,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { registerDirective } from '@ibyar/core/node.js';\nimport { directiveRegistry } from '@ibyar/elements/node.js';\nimport { DecoratorInfo } from '../transformer/modules.js';\nimport { metadataHoler } from '@ibyar/decorators';\n\nexport interface DirectiveInfo {\n\tselector: string,\n\tsuccessor?: string,\n\tinputs?: DecoratorInfo[],\n\toutputs?: DecoratorInfo[],\n}\nexport function registerDirectiveCall(info: DirectiveInfo) {\n\tdirectiveRegistry.register(info.selector, {\n\t\tsuccessor: info.successor,\n\t\tinputs: info.inputs?.map(i => i.aliasName),\n\t\toutputs: info.outputs?.map(i => i.aliasName),\n\t});\n\tconst modelClass = {};\n\tconst modelKey = {};\n\t(modelClass as any)[Symbol.metadata] = modelKey;\n\tconst metadata = metadataHoler.getOrCreate(modelKey);\n\tmetadata.modelClass = modelClass;\n\tmetadata.selector = info.selector;\n\tmetadata.inputs = info.inputs?.map(input => ({ modelProperty: input.name, viewAttribute: input.aliasName }));\n\tregisterDirective(modelClass);\n}\n"]}
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../../../src/cli/directives/register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AASlD,MAAM,UAAU,qBAAqB,CAAC,IAAmB;IACxD,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;QACpC,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1C,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;KAC5C,CAAC,CAAC;IAEH,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,QAAQ,GAAG,EAAE,CAAC;IACnB,UAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IAChD,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrD,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;IAClC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAC7G,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import { deleteDirective, provideDirective } from '@ibyar/core/node.js';\nimport { directiveRegistry } from '@ibyar/elements/node.js';\nimport { DecoratorInfo } from '../transformer/modules.js';\nimport { metadataHoler } from '@ibyar/decorators';\n\nexport interface DirectiveInfo {\n\tselector: string,\n\tsuccessor?: string,\n\tinputs?: DecoratorInfo[],\n\toutputs?: DecoratorInfo[],\n}\n\nexport function registerDirectiveCall(info: DirectiveInfo) {\n\tdirectiveRegistry.set(info.selector, {\n\t\tsuccessor: info.successor,\n\t\tinputs: info.inputs?.map(i => i.aliasName),\n\t\toutputs: info.outputs?.map(i => i.aliasName),\n\t});\n\n\tdeleteDirective(info.selector);\n\tconst modelClass = {};\n\tconst modelKey = {};\n\t(modelClass as any)[Symbol.metadata] = modelKey;\n\tconst metadata = metadataHoler.getOrCreate(modelKey);\n\tmetadata.modelClass = modelClass;\n\tmetadata.selector = info.selector;\n\tmetadata.inputs = info.inputs?.map(input => ({ modelProperty: input.name, viewAttribute: input.aliasName }));\n\tprovideDirective(modelClass);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibyar/cli",
3
- "version": "2.2.1",
3
+ "version": "2.3.0",
4
4
  "description": "The Ibyar/Aurora CLI tool",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/ibyar/aurora",
@@ -36,12 +36,12 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@ibyar/core": "^2.2.1",
40
- "@ibyar/decorators": "^2.2.1",
41
- "@ibyar/directives": "^2.2.1",
42
- "@ibyar/elements": "^2.2.1",
43
- "@ibyar/expressions": "^2.2.1",
44
- "@ibyar/pipes": "^2.2.1",
39
+ "@ibyar/core": "^2.3.0",
40
+ "@ibyar/decorators": "^2.3.0",
41
+ "@ibyar/directives": "^2.3.0",
42
+ "@ibyar/elements": "^2.3.0",
43
+ "@ibyar/expressions": "^2.3.0",
44
+ "@ibyar/pipes": "^2.3.0",
45
45
  "tslib": "^2.6.3",
46
46
  "typescript": "^5.5.2"
47
47
  },
@@ -74,5 +74,5 @@
74
74
  "shadow-dom",
75
75
  "typescript"
76
76
  ],
77
- "gitHead": "6c3b1c8d19faf00022c58ba2b893f4bb56147600"
77
+ "gitHead": "5bf90bcb6f9139753886e2e38272399af4c7153b"
78
78
  }
@@ -1,3 +0,0 @@
1
- import * as ts from "typescript";
2
- export declare function delint(sourceFile: ts.SourceFile): void;
3
- //# sourceMappingURL=directives.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../../../src/cli/directives/directives.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,wBAAgB,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,QAgD/C"}
@@ -1,48 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import * as ts from "typescript";
3
- export function delint(sourceFile) {
4
- delintNode(sourceFile);
5
- function delintNode(node) {
6
- switch (node.kind) {
7
- case ts.SyntaxKind.ForStatement:
8
- case ts.SyntaxKind.ForInStatement:
9
- case ts.SyntaxKind.WhileStatement:
10
- case ts.SyntaxKind.DoStatement:
11
- if (node.statement.kind !== ts.SyntaxKind.Block) {
12
- report(node, 'A looping statement\'s contents should be wrapped in a block body.');
13
- }
14
- break;
15
- case ts.SyntaxKind.IfStatement:
16
- const ifStatement = node;
17
- if (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {
18
- report(ifStatement.thenStatement, 'An if statement\'s contents should be wrapped in a block body.');
19
- }
20
- if (ifStatement.elseStatement &&
21
- ifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&
22
- ifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement) {
23
- report(ifStatement.elseStatement, 'An else statement\'s contents should be wrapped in a block body.');
24
- }
25
- break;
26
- case ts.SyntaxKind.BinaryExpression:
27
- const op = node.operatorToken.kind;
28
- if (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {
29
- report(node, 'Use \'===\' and \'!==\'.');
30
- }
31
- break;
32
- }
33
- ts.forEachChild(node, delintNode);
34
- }
35
- function report(node, message) {
36
- const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
37
- console.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);
38
- }
39
- }
40
- const fileNames = process.argv.slice(2);
41
- fileNames.forEach(fileName => {
42
- // Parse a file
43
- const sourceFile = ts.createSourceFile(fileName, readFileSync(fileName).toString(), ts.ScriptTarget.ES2015,
44
- /*setParentNodes */ true);
45
- // delint it
46
- delint(sourceFile);
47
- });
48
- //# sourceMappingURL=directives.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../src/cli/directives/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,MAAM,UAAU,MAAM,CAAC,UAAyB;IAC/C,UAAU,CAAC,UAAU,CAAC,CAAC;IACvB,SAAS,UAAU,CAAC,IAAa;QAChC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC;YAChC,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;YAClC,KAAK,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;YAClC,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW;gBAC7B,IAAK,IAA8B,CAAC,SAAS,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,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GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC;IAClF,CAAC;AACF,CAAC;AAED,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;IAC5B,eAAe;IACf,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CACrC,QAAQ,EACR,YAAY,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,EACjC,EAAE,CAAC,YAAY,CAAC,MAAM;IACpB,mBAAmB,CAAC,IAAI,CAC1B,CAAC;IAEF,YAAY;IACZ,MAAM,CAAC,UAAU,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC","sourcesContent":["import { readFileSync } from \"fs\";\nimport * as ts from \"typescript\";\n\nexport function delint(sourceFile: ts.SourceFile) {\n\tdelintNode(sourceFile);\n\tfunction delintNode(node: ts.Node) {\n\t\tswitch (node.kind) {\n\t\t\tcase ts.SyntaxKind.ForStatement:\n\t\t\tcase ts.SyntaxKind.ForInStatement:\n\t\t\tcase ts.SyntaxKind.WhileStatement:\n\t\t\tcase ts.SyntaxKind.DoStatement:\n\t\t\t\tif ((node as ts.IterationStatement).statement.kind !== ts.SyntaxKind.Block) {\n\t\t\t\t\treport(\n\t\t\t\t\t\tnode,\n\t\t\t\t\t\t'A looping statement\\'s contents should be wrapped in a block body.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase ts.SyntaxKind.IfStatement:\n\t\t\t\tconst ifStatement = node as ts.IfStatement;\n\t\t\t\tif (ifStatement.thenStatement.kind !== ts.SyntaxKind.Block) {\n\t\t\t\t\treport(ifStatement.thenStatement, 'An if statement\\'s contents should be wrapped in a block body.');\n\t\t\t\t}\n\t\t\t\tif (\n\t\t\t\t\tifStatement.elseStatement &&\n\t\t\t\t\tifStatement.elseStatement.kind !== ts.SyntaxKind.Block &&\n\t\t\t\t\tifStatement.elseStatement.kind !== ts.SyntaxKind.IfStatement\n\t\t\t\t) {\n\t\t\t\t\treport(\n\t\t\t\t\t\tifStatement.elseStatement,\n\t\t\t\t\t\t'An else statement\\'s contents should be wrapped in a block body.'\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase ts.SyntaxKind.BinaryExpression:\n\t\t\t\tconst op = (node as ts.BinaryExpression).operatorToken.kind;\n\t\t\t\tif (op === ts.SyntaxKind.EqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken) {\n\t\t\t\t\treport(node, 'Use \\'===\\' and \\'!==\\'.');\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t}\n\n\t\tts.forEachChild(node, delintNode);\n\t}\n\n\tfunction report(node: ts.Node, message: string) {\n\t\tconst { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());\n\t\tconsole.log(`${sourceFile.fileName} (${line + 1},${character + 1}): ${message}`);\n\t}\n}\n\nconst fileNames = process.argv.slice(2);\nfileNames.forEach(fileName => {\n\t// Parse a file\n\tconst sourceFile = ts.createSourceFile(\n\t\tfileName,\n\t\treadFileSync(fileName).toString(),\n\t\tts.ScriptTarget.ES2015,\n /*setParentNodes */ true\n\t);\n\n\t// delint it\n\tdelint(sourceFile);\n});"]}
@@ -1,9 +0,0 @@
1
- import ts from 'typescript/lib/tsserverlibrary.js';
2
- /**
3
- * search for `@Component({})` and update definition files
4
- * @param program a ts program
5
- * @returns a transformer factory of source file
6
- */
7
- export declare function afterDeclarationsCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
8
- export default afterDeclarationsCompileComponentOptions;
9
- //# sourceMappingURL=after-declarations-component%20copy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"after-declarations-component copy.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/after-declarations-component copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAKnD;;;;GAIG;AACH,wBAAgB,wCAAwC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAoElH;AAED,eAAe,wCAAwC,CAAC"}
@@ -1,56 +0,0 @@
1
- import ts from 'typescript/lib/tsserverlibrary.js';
2
- import { createStaticPropertyViewType, updateModule } from './factory.js';
3
- import { moduleManger } from './modules.js';
4
- /**
5
- * search for `@Component({})` and update definition files
6
- * @param program a ts program
7
- * @returns a transformer factory of source file
8
- */
9
- export function afterDeclarationsCompileComponentOptions(program) {
10
- const typeChecker = program.getTypeChecker();
11
- return (context) => {
12
- return sourceFile => {
13
- const moduleInfo = moduleManger.get(sourceFile.fileName);
14
- moduleManger.delete(sourceFile.fileName);
15
- if (!moduleInfo) {
16
- return sourceFile;
17
- }
18
- else if (moduleInfo.skip || !moduleInfo.classes) {
19
- return sourceFile;
20
- }
21
- const classes = moduleInfo.classes.filter(c => c.type === 'component');
22
- const sourceViewInfos = classes.flatMap(c => c.views);
23
- const updateSourceFile = ts.visitNode(sourceFile, (node) => {
24
- return ts.visitEachChild(node, (childNode) => {
25
- if (!ts.isClassDeclaration(childNode)) {
26
- return childNode;
27
- }
28
- const info = classes.find(c => c.name === childNode.name?.getText());
29
- if (!info) {
30
- return childNode;
31
- }
32
- const viewInfos = info.views;
33
- const staticMembers = viewInfos.map(viewInfo => ts.factory.createPropertyDeclaration([
34
- ts.factory.createModifier(ts.SyntaxKind.StaticKeyword),
35
- ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)
36
- ], viewInfo.viewName, undefined, createStaticPropertyViewType(viewInfo.viewName), undefined)).map(staticMember => ts.setTextRange(staticMember, childNode));
37
- return ts.factory.updateClassDeclaration(childNode, childNode.modifiers, childNode.name, childNode.typeParameters, childNode.heritageClauses, [...staticMembers, ...childNode.members.slice()]);
38
- }, context);
39
- });
40
- if (sourceViewInfos.length) {
41
- const statements = updateSourceFile.statements?.slice() ?? [];
42
- // statements.push(createConstructorOfViewInterfaceDeclaration());
43
- // const interfaces = sourceViewInfos.map(info => {
44
- // return ts.setTextRange(info.interFaceType, updateSourceFile);
45
- // });
46
- // statements.push(...interfaces);
47
- // statements.push(...updateGlobalHTMLElementTagNameMap(sourceViewInfos.map(v => ({ tagName: v.selector, viewName: v.viewName }))));
48
- statements.push(...updateModule(classes));
49
- return ts.factory.updateSourceFile(sourceFile, statements, updateSourceFile.isDeclarationFile, updateSourceFile.typeReferenceDirectives, updateSourceFile.referencedFiles, updateSourceFile.hasNoDefaultLib, updateSourceFile.libReferenceDirectives);
50
- }
51
- return updateSourceFile;
52
- };
53
- };
54
- }
55
- export default afterDeclarationsCompileComponentOptions;
56
- //# sourceMappingURL=after-declarations-component%20copy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"after-declarations-component copy.js","sourceRoot":"","sources":["../../../src/cli/transformer/after-declarations-component copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAY,MAAM,cAAc,CAAC;AAGtD;;;;GAIG;AACH,MAAM,UAAU,wCAAwC,CAAC,OAAmB;IAC3E,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAC7C,OAAO,CAAC,OAAiC,EAAiC,EAAE;QAC3E,OAAO,UAAU,CAAC,EAAE;YACnB,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACzD,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACzC,IAAI,CAAC,UAAU,EAAE,CAAC;gBACjB,OAAO,UAAU,CAAC;YACnB,CAAC;iBAAM,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;gBACnD,OAAO,UAAU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AAC,YAAY,EAAE,SAAS,CAAC,CAAC,CAAC;oBACjE,OAAO,EAAE,CAAC,OAAO,CAAC,sBAAsB,CACvC,SAAS,EACT,SAAS,CAAC,SAAS,EACnB,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,cAAc,EACxB,SAAS,CAAC,eAAe,EACzB,CAAC,GAAG,aAAa,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAChD,CAAC;gBACH,CAAC,EAAE,OAAO,CAAC,CAAC;YACb,CAAC,CAAkB,CAAC;YACpB,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;gBAC5B,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBAC9D,kEAAkE;gBAClE,mDAAmD;gBACnD,iEAAiE;gBACjE,MAAM;gBACN,kCAAkC;gBAClC,oIAAoI;gBACpI,UAAU,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC1C,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;AAED,eAAe,wCAAwC,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { createStaticPropertyViewType, updateModule } from './factory.js';\nimport { moduleManger, ViewInfo } from './modules.js';\n\n\n/**\n * search for `@Component({})` and update definition files\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function afterDeclarationsCompileComponentOptions(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\tconst moduleInfo = moduleManger.get(sourceFile.fileName);\n\t\t\tmoduleManger.delete(sourceFile.fileName);\n\t\t\tif (!moduleInfo) {\n\t\t\t\treturn sourceFile;\n\t\t\t} else if (moduleInfo.skip || !moduleInfo.classes) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes = moduleInfo.classes.filter(c => c.type === 'component');\n\n\t\t\tconst sourceViewInfos: ViewInfo[] = classes.flatMap(c => c.views);\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\tif (!ts.isClassDeclaration(childNode)) {\n\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t}\n\t\t\t\t\tconst info = classes.find(c => c.name === childNode.name?.getText());\n\n\t\t\t\t\tif (!info) {\n\t\t\t\t\t\treturn childNode;\n\t\t\t\t\t}\n\t\t\t\t\tconst viewInfos: ViewInfo[] = info.views;\n\t\t\t\t\tconst staticMembers = viewInfos.map(viewInfo => ts.factory.createPropertyDeclaration(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.StaticKeyword),\n\t\t\t\t\t\t\tts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword)\n\t\t\t\t\t\t],\n\t\t\t\t\t\tviewInfo.viewName,\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\tcreateStaticPropertyViewType(viewInfo.viewName),\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t)).map(staticMember => ts.setTextRange(staticMember, childNode));\n\t\t\t\t\treturn ts.factory.updateClassDeclaration(\n\t\t\t\t\t\tchildNode,\n\t\t\t\t\t\tchildNode.modifiers,\n\t\t\t\t\t\tchildNode.name,\n\t\t\t\t\t\tchildNode.typeParameters,\n\t\t\t\t\t\tchildNode.heritageClauses,\n\t\t\t\t\t\t[...staticMembers, ...childNode.members.slice()],\n\t\t\t\t\t);\n\t\t\t\t}, context);\n\t\t\t}) as ts.SourceFile;\n\t\t\tif (sourceViewInfos.length) {\n\t\t\t\tconst statements = updateSourceFile.statements?.slice() ?? [];\n\t\t\t\t// statements.push(createConstructorOfViewInterfaceDeclaration());\n\t\t\t\t// const interfaces = sourceViewInfos.map(info => {\n\t\t\t\t// \treturn ts.setTextRange(info.interFaceType, updateSourceFile);\n\t\t\t\t// });\n\t\t\t\t// statements.push(...interfaces);\n\t\t\t\t// statements.push(...updateGlobalHTMLElementTagNameMap(sourceViewInfos.map(v => ({ tagName: v.selector, viewName: v.viewName }))));\n\t\t\t\tstatements.push(...updateModule(classes));\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\nexport default afterDeclarationsCompileComponentOptions;\n"]}
@@ -1,8 +0,0 @@
1
- import ts from 'typescript/lib/tsserverlibrary.js';
2
- /**
3
- * search for `@Directive({})` and update definition files
4
- * @param program a ts program
5
- * @returns a transformer factory of source file
6
- */
7
- export declare function afterDeclarationsCompileDirectiveOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
8
- //# sourceMappingURL=after-declarations-directie.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"after-declarations-directie.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/after-declarations-directie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAKnD;;;;GAIG;AACH,wBAAgB,wCAAwC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CA0BlH"}
@@ -1,26 +0,0 @@
1
- import ts from 'typescript/lib/tsserverlibrary.js';
2
- import { updateModuleTypeWithDirectives } from './factory.js';
3
- import { moduleManger } from './modules.js';
4
- /**
5
- * search for `@Directive({})` and update definition files
6
- * @param program a ts program
7
- * @returns a transformer factory of source file
8
- */
9
- export function afterDeclarationsCompileDirectiveOptions(program) {
10
- return (context) => {
11
- return sourceFile => {
12
- const moduleInfo = moduleManger.get(sourceFile.fileName);
13
- if (!moduleInfo?.classes?.length) {
14
- return sourceFile;
15
- }
16
- const classes = moduleInfo.classes.filter(c => c.type === 'directive');
17
- if (!(classes.length > 0)) {
18
- return sourceFile;
19
- }
20
- const statements = sourceFile.statements?.slice() ?? [];
21
- statements.push(...updateModuleTypeWithDirectives(classes));
22
- return ts.factory.updateSourceFile(sourceFile, statements, sourceFile.isDeclarationFile, sourceFile.typeReferenceDirectives, sourceFile.referencedFiles, sourceFile.hasNoDefaultLib, sourceFile.libReferenceDirectives);
23
- };
24
- };
25
- }
26
- //# sourceMappingURL=after-declarations-directie.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"after-declarations-directie.js","sourceRoot":"","sources":["../../../src/cli/transformer/after-declarations-directie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,8BAA8B,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;GAIG;AACH,MAAM,UAAU,wCAAwC,CAAC,OAAmB;IAC3E,OAAO,CAAC,OAAiC,EAAiC,EAAE;QAC3E,OAAO,UAAU,CAAC,EAAE;YACnB,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YACzD,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;gBAClC,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;YACvE,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC3B,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;YACxD,UAAU,CAAC,IAAI,CAAC,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5D,OAAO,EAAE,CAAC,OAAO,CAAC,gBAAgB,CACjC,UAAU,EACV,UAAU,EACV,UAAU,CAAC,iBAAiB,EAC5B,UAAU,CAAC,uBAAuB,EAClC,UAAU,CAAC,eAAe,EAC1B,UAAU,CAAC,eAAe,EAC1B,UAAU,CAAC,sBAAsB,CACjC,CAAC;QACH,CAAC,CAAC;IACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { updateModuleTypeWithDirectives } from './factory.js';\nimport { moduleManger } from './modules.js';\n\n\n/**\n * search for `@Directive({})` and update definition files\n * @param program a ts program \n * @returns a transformer factory of source file\n */\nexport function afterDeclarationsCompileDirectiveOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile> {\n\treturn (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n\t\treturn sourceFile => {\n\t\t\tconst moduleInfo = moduleManger.get(sourceFile.fileName);\n\t\t\tif (!moduleInfo?.classes?.length) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst classes = moduleInfo.classes.filter(c => c.type === 'directive');\n\t\t\tif (!(classes.length > 0)) {\n\t\t\t\treturn sourceFile;\n\t\t\t}\n\n\t\t\tconst statements = sourceFile.statements?.slice() ?? [];\n\t\t\tstatements.push(...updateModuleTypeWithDirectives(classes));\n\t\t\treturn ts.factory.updateSourceFile(\n\t\t\t\tsourceFile,\n\t\t\t\tstatements,\n\t\t\t\tsourceFile.isDeclarationFile,\n\t\t\t\tsourceFile.typeReferenceDirectives,\n\t\t\t\tsourceFile.referencedFiles,\n\t\t\t\tsourceFile.hasNoDefaultLib,\n\t\t\t\tsourceFile.libReferenceDirectives,\n\t\t\t);\n\t\t};\n\t};\n}\n"]}
@@ -1,9 +0,0 @@
1
- import ts from 'typescript/lib/tsserverlibrary.js';
2
- /**
3
- * search for `@Component({})` and precompile the source code
4
- * @param program a ts program
5
- * @returns a transformer factory of source file
6
- */
7
- export declare function beforeCompileComponentOptions(program: ts.Program): ts.TransformerFactory<ts.SourceFile>;
8
- export default beforeCompileComponentOptions;
9
- //# sourceMappingURL=before-component%20copy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"before-component copy.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/before-component copy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAkBnD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAoOvG;AAED,eAAe,6BAA6B,CAAC"}
@@ -1,212 +0,0 @@
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
@@ -1 +0,0 @@
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;AACjE,OAAO,EACN,oBAAoB,EAAE,oBAAoB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;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"]}