@ibyar/cli 2.2.0 → 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.
Files changed (33) hide show
  1. package/README.md +107 -12
  2. package/bin/cli.js +1 -9
  3. package/bin/cli.js.map +1 -1
  4. package/compiler/compiler.d.ts +6 -1
  5. package/compiler/compiler.d.ts.map +1 -1
  6. package/compiler/compiler.js +91 -5
  7. package/compiler/compiler.js.map +1 -1
  8. package/directives/register.d.ts.map +1 -1
  9. package/directives/register.js +4 -3
  10. package/directives/register.js.map +1 -1
  11. package/package.json +8 -8
  12. package/transformer/helpers.d.ts +2 -0
  13. package/transformer/helpers.d.ts.map +1 -1
  14. package/transformer/helpers.js +55 -19
  15. package/transformer/helpers.js.map +1 -1
  16. package/webpack/loader.js +2 -2
  17. package/webpack/loader.js.map +1 -1
  18. package/directives/directives.d.ts +0 -3
  19. package/directives/directives.d.ts.map +0 -1
  20. package/directives/directives.js +0 -48
  21. package/directives/directives.js.map +0 -1
  22. package/transformer/after-declarations-component copy.d.ts +0 -9
  23. package/transformer/after-declarations-component copy.d.ts.map +0 -1
  24. package/transformer/after-declarations-component copy.js +0 -56
  25. package/transformer/after-declarations-component copy.js.map +0 -1
  26. package/transformer/after-declarations-directie.d.ts +0 -8
  27. package/transformer/after-declarations-directie.d.ts.map +0 -1
  28. package/transformer/after-declarations-directie.js +0 -26
  29. package/transformer/after-declarations-directie.js.map +0 -1
  30. package/transformer/before-component copy.d.ts +0 -9
  31. package/transformer/before-component copy.d.ts.map +0 -1
  32. package/transformer/before-component copy.js +0 -212
  33. package/transformer/before-component copy.js.map +0 -1
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,26 +40,121 @@ 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
- -w --watch compile and watch source files, used with --build
52
- -gt --generate-types generate "web-types.json" files, and typescript
53
- definitions '.d.ts' files.
54
- you can import this file later in your "index.ts"
55
- or "polyfills.ts" file, so any editor "VS Code" can
56
- support autocomplete easily,
51
+ and generate '.d.ts' files with created Custom HTML Element definitions.
52
+ -w --watch compile and watch source files, used with --build
57
53
  -h --help print help message
58
54
  -v --version output the version number
59
55
  ```
60
56
 
61
57
 
62
58
 
59
+ ## Integration with `Webpack`
60
+
61
+
62
+ ### add @ibyar/cli as loader
63
+
64
+ ```js
65
+ module.exports = {
66
+ entry: './src/index.ts',
67
+ module: {
68
+ exprContextCritical: false,
69
+ rules: [
70
+ {
71
+ test: /\.tsx?$/,
72
+ use: ['@ibyar/cli',],
73
+ exclude: /node_modules/,
74
+ }
75
+ ]
76
+ }
77
+ };
78
+ ```
79
+
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
+
124
+
125
+ ```js
126
+ import typescript from '@rollup/plugin-typescript';
127
+ import {
128
+ beforeCompileDirectiveOptions, beforeCompileComponentOptions,
129
+ afterDeclarationsCompileComponentOptions,
130
+ afterDeclarationsCompileDirectiveOptions,
131
+ scanDirectivesOnceAsTransformer,
132
+ } from '@ibyar/cli';
133
+
134
+ export default = {
135
+ ...,
136
+ plugins: [
137
+ typescript({
138
+ transformers: {
139
+ before: [
140
+ { type: 'program', factory: scanDirectivesOnceAsTransformer() },
141
+ { type: 'program', factory: beforeCompileDirectiveOptions },
142
+ { type: 'program', factory: beforeCompileComponentOptions },
143
+ ],
144
+ after: [],
145
+ afterDeclarations: [
146
+ { type: 'program', factory: afterDeclarationsCompileComponentOptions },
147
+ { type: 'program', factory: afterDeclarationsCompileDirectiveOptions },
148
+ ],
149
+ }
150
+ }),
151
+ ],
152
+ };
153
+
154
+ ```
155
+
156
+
157
+
63
158
  The Ibyar CLI has a typescript transformer to generate a definitions for you component
64
159
 
65
160
  ```ts
package/bin/cli.js CHANGED
@@ -8,7 +8,6 @@ const inputs = args.slice(2);
8
8
  const showHelp = inputs.includes('-h') || inputs.includes('--help');
9
9
  const printVersion = inputs.length === 1 && (inputs.includes('-v') || inputs.includes('--version'));
10
10
  const runBuild = inputs.includes('-b') || inputs.includes('--build');
11
- const generateTypes = inputs.includes('-gt') || inputs.includes('--generate-types');
12
11
  if (showHelp) {
13
12
  const help = `
14
13
  Version ${readPackageVersion()}
@@ -24,12 +23,8 @@ Examples:
24
23
 
25
24
  Options:
26
25
  -b --build compile the project source code with ibyar transformers
26
+ and generate '.d.ts' files with created Custom HTML Element definitions.
27
27
  -w --watch compile and watch source files, used with --build
28
- -gt --generate-types generate "web-types.json" files, and typescript
29
- definitions '.d.ts' files.
30
- you can import this file later in your "index.ts"
31
- or "polyfills.ts" file, so any editor "VS Code" can
32
- support autocomplete easily,
33
28
  -h --help print help message
34
29
  -v --version output the version number`;
35
30
  console.log(help);
@@ -48,9 +43,6 @@ if (runBuild) {
48
43
  }
49
44
  }).catch(error => console.error(error));
50
45
  }
51
- if (generateTypes) {
52
- console.log('generate types not supported yet.');
53
- }
54
46
  function readPackageVersion() {
55
47
  const url = fileURLToPath(import.meta.url);
56
48
  const path = join(url, '..', '..', 'package.json');
package/bin/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/cli/bin/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;AAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAE7B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACpE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;AAEpG,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AACrE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E,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAwB,CAAC;IAC9D,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { join } from 'path';\nimport { exit } from 'process';\nimport { readFileSync } from 'fs';\nimport { fileURLToPath } from 'url';\n\nconst args = process.argv;\nconst inputs = args.slice(2);\n\nconst showHelp = inputs.includes('-h') || inputs.includes('--help');\nconst printVersion = inputs.length === 1 && (inputs.includes('-v') || inputs.includes('--version'));\n\nconst runBuild = inputs.includes('-b') || inputs.includes('--build');\nconst generateTypes = inputs.includes('-gt') || inputs.includes('--generate-types');\n\nif (showHelp) {\n\tconst help =\n\t\t`\nVersion ${readPackageVersion()}\nUsage: ibyar [options]\n\nExamples:\n ibyar\n ibyar -b\n ibyar -b -w\n ibyar -gt\n ibyar -v\n ibyar --help\n\nOptions:\n -b --build compile the project source code with ibyar transformers\n\t-w\t\t--watch\t\t\t\tcompile and watch source files, used with --build\n -gt --generate-types generate \"web-types.json\" files, and typescript\n\t definitions '.d.ts' files. \n\t you can import this file later in your \"index.ts\" \n\t\t\t\t\t\t\t\tor \"polyfills.ts\" file, so any editor \"VS Code\" can\n\t\t\t\t\t\t\t\tsupport autocomplete easily,\n -h --help print help message\n -v --version output the version number`;\n\tconsole.log(help);\n\texit();\n}\n\n\nif (printVersion) {\n\tconsole.log(readPackageVersion());\n}\n\nif (runBuild) {\n\timport('../compiler/compiler.js').then(module => {\n\t\tif (inputs.includes('-w') || inputs.includes('--watch')) {\n\t\t\tmodule.compileAndWatchArgs();\n\t\t} else {\n\t\t\tmodule.compileArgs();\n\t\t}\n\t}).catch(error => console.error(error));\n}\n\nif (generateTypes) {\n\tconsole.log('generate types not supported yet.');\n}\n\nfunction readPackageVersion(): string {\n\tconst url = fileURLToPath(import.meta.url);\n\tconst path = join(url, '..', '..', 'package.json');\n\tconst string = readFileSync(path, 'utf-8').toString();\n\tconst { version } = JSON.parse(string) as { version: string };\n\treturn version;\n}\n"]}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Q,CAAC,SAAS,CAAC,EAAE,CAAC;YACzD,MAAM,CAAC,mBAAmB,EAAE,CAAC;QAC9B,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,WAAW,EAAE,CAAC;QACtB,CAAC;IACF,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,kBAAkB;IAC1B,MAAM,GAAG,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC;IACtD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAwB,CAAC;IAC9D,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { join } from 'path';\nimport { exit } from 'process';\nimport { readFileSync } from 'fs';\nimport { fileURLToPath } from 'url';\n\nconst args = process.argv;\nconst inputs = args.slice(2);\n\nconst showHelp = inputs.includes('-h') || inputs.includes('--help');\nconst printVersion = inputs.length === 1 && (inputs.includes('-v') || inputs.includes('--version'));\n\nconst runBuild = inputs.includes('-b') || inputs.includes('--build');\n\nif (showHelp) {\n\tconst help =\n\t\t`\nVersion ${readPackageVersion()}\nUsage: ibyar [options]\n\nExamples:\n ibyar\n ibyar -b\n ibyar -b -w\n ibyar -gt\n ibyar -v\n ibyar --help\n\nOptions:\n -b --build compile the project source code with ibyar transformers\n\t and generate '.d.ts' files with created Custom HTML Element definitions.\n\t-w\t\t--watch\t\t\t\tcompile and watch source files, used with --build\n -h --help print help message\n -v --version output the version number`;\n\tconsole.log(help);\n\texit();\n}\n\n\nif (printVersion) {\n\tconsole.log(readPackageVersion());\n}\n\nif (runBuild) {\n\timport('../compiler/compiler.js').then(module => {\n\t\tif (inputs.includes('-w') || inputs.includes('--watch')) {\n\t\t\tmodule.compileAndWatchArgs();\n\t\t} else {\n\t\t\tmodule.compileArgs();\n\t\t}\n\t}).catch(error => console.error(error));\n}\n\nfunction readPackageVersion(): string {\n\tconst url = fileURLToPath(import.meta.url);\n\tconst path = join(url, '..', '..', 'package.json');\n\tconst string = readFileSync(path, 'utf-8').toString();\n\tconst { version } = JSON.parse(string) as { version: string };\n\treturn version;\n}\n"]}
@@ -1,10 +1,15 @@
1
1
  import '../directives/register.js';
2
2
  import ts from 'typescript/lib/tsserverlibrary.js';
3
3
  export declare function getTransformers(program: ts.Program): ts.CustomTransformers;
4
- export declare function scanDirective(program: ts.Program): void;
4
+ export declare function scanDirectives(program: ts.Program): void;
5
+ export declare function scanDirectivesOnceAsTransformer(): (program: ts.Program) => (context: ts.TransformationContext) => ts.Transformer<ts.SourceFile>;
5
6
  export declare function emitProgram(program: ts.Program): void;
6
7
  export declare function compileFiles(files: readonly string[], options: ts.CompilerOptions): void;
7
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;
8
13
  export declare function getConfigPath(): string;
9
14
  export declare function compileArgs(): void;
10
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,aAAa,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,QAEhD;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: [
@@ -18,11 +20,23 @@ export function getTransformers(program) {
18
20
  ],
19
21
  };
20
22
  }
21
- export function scanDirective(program) {
23
+ export function scanDirectives(program) {
22
24
  program.getSourceFiles().forEach(scanDirectivesTypeVisitor);
23
25
  }
26
+ export function scanDirectivesOnceAsTransformer() {
27
+ let scanDone = false;
28
+ let ignoreTransformer = (context) => sourceFile => sourceFile;
29
+ return (program) => {
30
+ if (scanDone) {
31
+ return ignoreTransformer;
32
+ }
33
+ scanDone = true;
34
+ scanDirectives(program);
35
+ return ignoreTransformer;
36
+ };
37
+ }
24
38
  export function emitProgram(program) {
25
- scanDirective(program);
39
+ scanDirectives(program);
26
40
  program.emit(undefined, undefined, undefined, undefined, getTransformers(program));
27
41
  }
28
42
  export function compileFiles(files, options) {
@@ -53,8 +67,70 @@ export function compileAndWatchFiles(configPath, cmd) {
53
67
  const program = programBuilder.getProgram();
54
68
  emitProgram(program);
55
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
+ }
56
125
  export function getConfigPath() {
57
- 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
+ }
58
134
  const configPath = ts.findConfigFile('./', /*searchPath*/ ts.sys.fileExists, tsconfig ?? 'tsconfig.json');
59
135
  if (!configPath) {
60
136
  throw new Error("Could not find a valid 'tsconfig.json'.");
@@ -67,7 +143,12 @@ export function compileArgs() {
67
143
  if (!cmd) {
68
144
  return;
69
145
  }
70
- compileFiles(cmd.fileNames, cmd.options);
146
+ if (cmd.projectReferences?.length) {
147
+ compileSolution(configPath, cmd);
148
+ }
149
+ else {
150
+ compileFiles(cmd.fileNames, cmd.options);
151
+ }
71
152
  }
72
153
  export function compileAndWatchArgs() {
73
154
  const configPath = getConfigPath();
@@ -75,6 +156,11 @@ export function compileAndWatchArgs() {
75
156
  if (!cmd) {
76
157
  return;
77
158
  }
78
- compileAndWatchFiles(configPath, cmd);
159
+ if (cmd.projectReferences?.length) {
160
+ compileSolutionAndWatch(configPath, cmd);
161
+ }
162
+ else {
163
+ compileAndWatchFiles(configPath, cmd);
164
+ }
79
165
  }
80
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,aAAa,CAAC,OAAmB;IAChD,OAAO,CAAC,cAAc,EAAE,CAAC,OAAO,CAAC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E,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 scanDirective(program: ts.Program) {\n\tprogram.getSourceFiles().forEach(scanDirectivesTypeVisitor);\n}\n\nexport function emitProgram(program: ts.Program) {\n\tscanDirective(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":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AAG,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.0",
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.0",
40
- "@ibyar/decorators": "^2.2.0",
41
- "@ibyar/directives": "^2.2.0",
42
- "@ibyar/elements": "^2.2.0",
43
- "@ibyar/expressions": "^2.2.0",
44
- "@ibyar/pipes": "^2.2.0",
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": "70db847b00908addff4aed9e7e4f545edb5f2526"
77
+ "gitHead": "5bf90bcb6f9139753886e2e38272399af4c7153b"
78
78
  }
@@ -41,6 +41,8 @@ export declare function isInputDecorator(decorator: ts.Decorator): boolean;
41
41
  * @returns
42
42
  */
43
43
  export declare function isOutputDecorator(decorator: ts.Decorator): boolean;
44
+ export declare function getMapByDecoratorForPropertyDeclaration(member: ts.PropertyDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): DecoratorInfo[];
45
+ export declare function getMapByDecoratorForSetAccessorDeclaration(member: ts.SetAccessorDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): DecoratorInfo[];
44
46
  export declare function getMapByDecorator(classNode: ts.ClassDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): DecoratorInfo[];
45
47
  /**
46
48
  * get a component or directive inputs that is annotated by `@Input` or `@FormValue`.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/cli/transformer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,aAAa,SAAc,GAAG,OAAO,CAElG;AAGD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,aAAa,SAAc,GAAG,OAAO,CAElG;AAED,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,aAAa,SAAc,EAAE,aAAa,SAAc,GAAG,OAAO,CAE1I;AAGD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,QAAQ,SAAS,GAAG,OAAO,CAEnF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,cAAc,SAAe,GAAG,OAAO,CAErG;AAGD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,GAA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G,aAAa,EAAE,CAUnK;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,GAAG,aAAa,EAAE,CAElG;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,GAAG,MAAM,EAAE,CAE/F;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,GAAG,aAAa,EAAE,CAEnG;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,EAAE,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,GAAG,MAAM,EAAE,CAEhG;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAShH"}
@@ -60,30 +60,66 @@ export function isInputDecorator(decorator) {
60
60
  export function isOutputDecorator(decorator) {
61
61
  return ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === 'Output';
62
62
  }
63
+ export function getMapByDecoratorForPropertyDeclaration(member, checker, decoratorFilter) {
64
+ const infos = [];
65
+ const decorators = ts.getDecorators(member);
66
+ if (!decorators) {
67
+ return infos;
68
+ }
69
+ const inputDecorators = decorators.filter(decoratorFilter);
70
+ if (!inputDecorators.length) {
71
+ return infos;
72
+ }
73
+ let inputType = member.type?.getText();
74
+ if (!inputType && member.initializer) {
75
+ inputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);
76
+ }
77
+ inputDecorators.forEach(input => {
78
+ const decoratorCall = input.expression;
79
+ const aliasName = decoratorCall.arguments[0];
80
+ const alias = aliasName ? aliasName.text : member.name.getText();
81
+ infos.push({ name: member.name.getText(), aliasName: alias, type: inputType });
82
+ });
83
+ return infos;
84
+ }
85
+ export function getMapByDecoratorForSetAccessorDeclaration(member, checker, decoratorFilter) {
86
+ const infos = [];
87
+ const decorators = ts.getDecorators(member);
88
+ if (!decorators) {
89
+ return infos;
90
+ }
91
+ const inputDecorators = decorators.filter(decoratorFilter);
92
+ if (!inputDecorators.length) {
93
+ return infos;
94
+ }
95
+ let memberName;
96
+ if (ts.isIdentifier(member.name)) {
97
+ memberName = member.name.getText();
98
+ }
99
+ else if (ts.isComputedPropertyName(member.name) && ts.isStringLiteral(member.name.expression)) {
100
+ memberName = member.name.expression.getText();
101
+ }
102
+ else {
103
+ return infos;
104
+ }
105
+ let inputType = checker.typeToString(checker.getTypeAtLocation(member.parameters[0]), member.parameters[0], undefined);
106
+ inputDecorators.forEach(input => {
107
+ const decoratorCall = input.expression;
108
+ const aliasName = decoratorCall.arguments[0];
109
+ const alias = aliasName ? aliasName.text : memberName;
110
+ infos.push({ name: memberName, aliasName: alias, type: inputType });
111
+ });
112
+ return infos;
113
+ }
63
114
  export function getMapByDecorator(classNode, checker, decoratorFilter) {
64
115
  const infos = [];
65
116
  classNode.members.forEach(member => {
66
- if (!ts.isPropertyDeclaration(member)) {
67
- return;
68
- }
69
- const decorators = ts.getDecorators(member);
70
- if (!decorators) {
71
- return;
72
- }
73
- const inputDecorators = decorators.filter(decoratorFilter);
74
- if (!inputDecorators.length) {
75
- return;
117
+ if (ts.isPropertyDeclaration(member)) {
118
+ infos.push(...getMapByDecoratorForPropertyDeclaration(member, checker, decoratorFilter));
76
119
  }
77
- let inputType = member.type?.getText();
78
- if (!inputType && member.initializer) {
79
- inputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);
120
+ else if (ts.isSetAccessorDeclaration(member)) {
121
+ infos.push(...getMapByDecoratorForSetAccessorDeclaration(member, checker, decoratorFilter));
80
122
  }
81
- inputDecorators.forEach(input => {
82
- const decoratorCall = input.expression;
83
- const aliasName = decoratorCall.arguments[0];
84
- const alias = aliasName ? aliasName.text : member.name.getText();
85
- infos.push({ name: member.name.getText(), aliasName: alias, type: inputType });
86
- });
87
123
  });
88
124
  return infos;
89
125
  }
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/cli/transformer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAInD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAuB,EAAE,aAAa,GAAG,WAAW;IACxF,OAAO,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,aAAa,CAAC;AACjH,CAAC;AAAA,CAAC;AAGF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAuB,EAAE,aAAa,GAAG,WAAW;IACxF,OAAO,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,aAAa,CAAC;AACjH,CAAC;AAAA,CAAC;AAEF,MAAM,UAAU,+BAA+B,CAAC,SAAuB,EAAE,aAAa,GAAG,WAAW,EAAE,aAAa,GAAG,WAAW;IAChI,OAAO,oBAAoB,CAAC,SAAS,EAAE,aAAa,CAAC,IAAI,oBAAoB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AACzG,CAAC;AAAA,CAAC;AAGF;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,SAAuB,EAAE,QAAQ,GAAG,MAAM;IACzE,OAAO,EAAE,CAAC,gBAAgB,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC;AAC5G,CAAC;AAAA,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,qBAAq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BAAiB,CAAC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,SAA8B,EAAE,OAAuB;IACrF,OAAO,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAkC,EAAE,QAAgB;IAC3F,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU;SACxC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,QAAQ,CAAsC,CAAC;IAEvF,MAAM,WAAW,GAAG,gBAAgB,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC;IAC5D,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO;IACR,CAAC;IACD,OAAO,WAAW,EAAE,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { DecoratorInfo } from './modules.js';\n\n\n/**\n * check if a decorator is a `@Component` decorator;\n * @param decorator \n * @param expressionName \n * @returns \n */\nexport function isComponentDecorator(decorator: ts.Decorator, componentName = 'Component'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === componentName;\n};\n\n\n/**\n * check if a decorator is a `@Directive` decorator;\n * @param decorator \n * @param directiveName \n * @returns \n */\nexport function isDirectiveDecorator(decorator: ts.Decorator, directiveName = 'Directive'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === directiveName;\n};\n\nexport function isComponentOrDirectiveDecorator(decorator: ts.Decorator, componentName = 'Component', directiveName = 'Directive'): boolean {\n\treturn isComponentDecorator(decorator, componentName) || isDirectiveDecorator(decorator, directiveName);\n};\n\n\n/**\n * check if a decorator is a `@Pipe` decorator;\n * @param decorator \n * @param pipeName \n * @returns \n */\nexport function isPipeDecorator(decorator: ts.Decorator, pipeName = 'Pipe'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === pipeName;\n};\n\n/**\n * check if a decorator is a `@Injectable` decorator;\n * @param decorator \n * @param injectableName \n * @returns \n */\nexport function isInjectableDecorator(decorator: ts.Decorator, injectableName = 'Injectable'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === injectableName;\n};\n\n\n/**\n * check if Decorator is `@Input` or `@FormValue`\n * @param decorator \n * @returns \n */\nexport function isInputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && (\n\t\tdecorator.expression.expression.getText() === 'Input'\n\t\t|| decorator.expression.expression.getText() === 'FormValue'\n\t);\n}\n\n/**\n * check if Decorator is `@Output`\n * @param decorator \n * @returns \n */\nexport function isOutputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === 'Output';\n}\n\nexport function getMapByDecorator(classNode: ts.ClassDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): DecoratorInfo[] {\n\tconst infos: DecoratorInfo[] = [];\n\tclassNode.members.forEach(member => {\n\t\tif (!ts.isPropertyDeclaration(member)) {\n\t\t\treturn;\n\t\t}\n\t\tconst decorators = ts.getDecorators(member);\n\t\tif (!decorators) {\n\t\t\treturn;\n\t\t}\n\t\tconst inputDecorators = decorators.filter(decoratorFilter);\n\t\tif (!inputDecorators.length) {\n\t\t\treturn;\n\t\t}\n\t\tlet inputType = member.type?.getText();\n\t\tif (!inputType && member.initializer) {\n\t\t\tinputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);\n\t\t}\n\t\tinputDecorators.forEach(input => {\n\t\t\tconst decoratorCall = input.expression as ts.CallExpression;\n\t\t\tconst aliasName = decoratorCall.arguments[0] as ts.StringLiteralLike;\n\t\t\tconst alias = aliasName ? aliasName.text : member.name.getText();\n\t\t\tinfos.push({ name: member.name.getText(), aliasName: alias, type: inputType });\n\t\t});\n\t})\n\treturn infos;\n}\n\n/**\n * get a component or directive inputs that is annotated by `@Input` or `@FormValue`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getInputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): DecoratorInfo[] {\n\treturn getMapByDecorator(classNode, checker, isInputDecorator);\n}\n\n/**\n * get a component or directive input names that is annotated by `@Input` or `@FormValue`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getInputNames(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): string[] {\n\treturn getInputs(classNode, checker).map(info => info.aliasName);\n}\n\n/**\n * get a component or directive outputs that is annotated by `@Output`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getOutputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): DecoratorInfo[] {\n\treturn getMapByDecorator(classNode, checker, isOutputDecorator);\n}\n\n/**\n * get a component or directive output names that is annotated by `@Output`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getOutputNames(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): string[] {\n\treturn getOutputs(classNode, checker).map(info => info.aliasName);\n}\n\n/**\n * get text value for a property in ObjectLiteralExpression\n * @param option \n * @param property \n * @returns \n */\nexport function getTextValueForProperty(option: ts.ObjectLiteralExpression, property: string): string | undefined {\n\tconst selectorProperty = option.properties\n\t\t.find(prop => prop.name?.getText() === property) as ts.PropertyAssignment | undefined;\n\n\tconst initializer = selectorProperty?.initializer.getText();\n\tif (!initializer) {\n\t\treturn;\n\t}\n\treturn initializer?.substring(1, initializer.length - 1);\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/cli/transformer/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAInD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAA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CAAC;AAChE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,SAA8B,EAAE,OAAuB;IACpF,OAAO,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAClE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,SAA8B,EAAE,OAAuB;IACjF,OAAO,iBAAiB,CAAC,SAAS,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACjE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,SAA8B,EAAE,OAAuB;IACrF,OAAO,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAkC,EAAE,QAAgB;IAC3F,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU;SACxC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,QAAQ,CAAsC,CAAC;IAEvF,MAAM,WAAW,GAAG,gBAAgB,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC;IAC5D,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO;IACR,CAAC;IACD,OAAO,WAAW,EAAE,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import ts from 'typescript/lib/tsserverlibrary.js';\nimport { DecoratorInfo } from './modules.js';\n\n\n/**\n * check if a decorator is a `@Component` decorator;\n * @param decorator \n * @param expressionName \n * @returns \n */\nexport function isComponentDecorator(decorator: ts.Decorator, componentName = 'Component'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === componentName;\n};\n\n\n/**\n * check if a decorator is a `@Directive` decorator;\n * @param decorator \n * @param directiveName \n * @returns \n */\nexport function isDirectiveDecorator(decorator: ts.Decorator, directiveName = 'Directive'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === directiveName;\n};\n\nexport function isComponentOrDirectiveDecorator(decorator: ts.Decorator, componentName = 'Component', directiveName = 'Directive'): boolean {\n\treturn isComponentDecorator(decorator, componentName) || isDirectiveDecorator(decorator, directiveName);\n};\n\n\n/**\n * check if a decorator is a `@Pipe` decorator;\n * @param decorator \n * @param pipeName \n * @returns \n */\nexport function isPipeDecorator(decorator: ts.Decorator, pipeName = 'Pipe'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === pipeName;\n};\n\n/**\n * check if a decorator is a `@Injectable` decorator;\n * @param decorator \n * @param injectableName \n * @returns \n */\nexport function isInjectableDecorator(decorator: ts.Decorator, injectableName = 'Injectable'): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === injectableName;\n};\n\n\n/**\n * check if Decorator is `@Input` or `@FormValue`\n * @param decorator \n * @returns \n */\nexport function isInputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && (\n\t\tdecorator.expression.expression.getText() === 'Input'\n\t\t|| decorator.expression.expression.getText() === 'FormValue'\n\t);\n}\n\n/**\n * check if Decorator is `@Output`\n * @param decorator \n * @returns \n */\nexport function isOutputDecorator(decorator: ts.Decorator): boolean {\n\treturn ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() === 'Output';\n}\n\nexport function getMapByDecoratorForPropertyDeclaration(member: ts.PropertyDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): DecoratorInfo[] {\n\tconst infos: DecoratorInfo[] = [];\n\tconst decorators = ts.getDecorators(member);\n\tif (!decorators) {\n\t\treturn infos;\n\t}\n\tconst inputDecorators = decorators.filter(decoratorFilter);\n\tif (!inputDecorators.length) {\n\t\treturn infos;\n\t}\n\tlet inputType = member.type?.getText();\n\tif (!inputType && member.initializer) {\n\t\tinputType = checker.typeToString(checker.getTypeAtLocation(member.initializer), member.initializer, undefined);\n\t}\n\tinputDecorators.forEach(input => {\n\t\tconst decoratorCall = input.expression as ts.CallExpression;\n\t\tconst aliasName = decoratorCall.arguments[0] as ts.StringLiteralLike;\n\t\tconst alias = aliasName ? aliasName.text : member.name.getText();\n\t\tinfos.push({ name: member.name.getText(), aliasName: alias, type: inputType });\n\t});\n\treturn infos;\n}\n\nexport function getMapByDecoratorForSetAccessorDeclaration(member: ts.SetAccessorDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): DecoratorInfo[] {\n\tconst infos: DecoratorInfo[] = [];\n\tconst decorators = ts.getDecorators(member);\n\tif (!decorators) {\n\t\treturn infos;\n\t}\n\tconst inputDecorators = decorators.filter(decoratorFilter);\n\tif (!inputDecorators.length) {\n\t\treturn infos;\n\t}\n\n\tlet memberName: string;\n\tif (ts.isIdentifier(member.name)) {\n\t\tmemberName = member.name.getText();\n\t} else if (ts.isComputedPropertyName(member.name) && ts.isStringLiteral(member.name.expression)) {\n\t\tmemberName = member.name.expression.getText();\n\t} else {\n\t\treturn infos;\n\t}\n\n\tlet inputType = checker.typeToString(checker.getTypeAtLocation(member.parameters[0]), member.parameters[0], undefined);\n\tinputDecorators.forEach(input => {\n\t\tconst decoratorCall = input.expression as ts.CallExpression;\n\t\tconst aliasName = decoratorCall.arguments[0] as ts.StringLiteralLike;\n\t\tconst alias = aliasName ? aliasName.text : memberName;\n\t\tinfos.push({ name: memberName, aliasName: alias, type: inputType });\n\t});\n\treturn infos;\n}\n\nexport function getMapByDecorator(classNode: ts.ClassDeclaration, checker: ts.TypeChecker, decoratorFilter: ((decorator: ts.Decorator) => boolean)): DecoratorInfo[] {\n\tconst infos: DecoratorInfo[] = [];\n\tclassNode.members.forEach(member => {\n\t\tif (ts.isPropertyDeclaration(member)) {\n\t\t\tinfos.push(...getMapByDecoratorForPropertyDeclaration(member, checker, decoratorFilter));\n\t\t} else if (ts.isSetAccessorDeclaration(member)) {\n\t\t\tinfos.push(...getMapByDecoratorForSetAccessorDeclaration(member, checker, decoratorFilter));\n\t\t}\n\t})\n\treturn infos;\n}\n\n/**\n * get a component or directive inputs that is annotated by `@Input` or `@FormValue`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getInputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): DecoratorInfo[] {\n\treturn getMapByDecorator(classNode, checker, isInputDecorator);\n}\n\n/**\n * get a component or directive input names that is annotated by `@Input` or `@FormValue`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getInputNames(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): string[] {\n\treturn getInputs(classNode, checker).map(info => info.aliasName);\n}\n\n/**\n * get a component or directive outputs that is annotated by `@Output`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getOutputs(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): DecoratorInfo[] {\n\treturn getMapByDecorator(classNode, checker, isOutputDecorator);\n}\n\n/**\n * get a component or directive output names that is annotated by `@Output`.\n * @param classNode \n * @param checker \n * @returns \n */\nexport function getOutputNames(classNode: ts.ClassDeclaration, checker: ts.TypeChecker): string[] {\n\treturn getOutputs(classNode, checker).map(info => info.aliasName);\n}\n\n/**\n * get text value for a property in ObjectLiteralExpression\n * @param option \n * @param property \n * @returns \n */\nexport function getTextValueForProperty(option: ts.ObjectLiteralExpression, property: string): string | undefined {\n\tconst selectorProperty = option.properties\n\t\t.find(prop => prop.name?.getText() === property) as ts.PropertyAssignment | undefined;\n\n\tconst initializer = selectorProperty?.initializer.getText();\n\tif (!initializer) {\n\t\treturn;\n\t}\n\treturn initializer?.substring(1, initializer.length - 1);\n}\n"]}
package/webpack/loader.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { normalize } from 'path';
2
2
  import ts from 'typescript/lib/tsserverlibrary.js';
3
- import { getConfigPath, getTransformers, scanDirective } from '../compiler/compiler.js';
3
+ import { getConfigPath, getTransformers, scanDirectives } from '../compiler/compiler.js';
4
4
  let host;
5
5
  let program;
6
6
  let orgWriteFile;
@@ -19,7 +19,7 @@ export function initTypeScript() {
19
19
  orgWriteFile = host.writeFile;
20
20
  program = ts.createProgram(cmd.fileNames, cmd.options, host);
21
21
  transformers = getTransformers(program);
22
- scanDirective(program);
22
+ scanDirectives(program);
23
23
  }
24
24
  export function loader(contents, inputSourceMap) {
25
25
  if (!program) {
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/cli/webpack/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExF,IAAI,IAAqB,CAAC;AAC1B,IAAI,OAAmB,CAAC;AACxB,IAAI,YAAkC,CAAC;AACvC,IAAI,YAAmC,CAAC;AAExC;;GAEG;AAEH,MAAM,UAAU,cAAc;IAC7B,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,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;QACzC,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC;IACD,IAAI,GAAG,EAAE,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1C,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;IAC9B,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC7D,YAAY,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACxC,aAAa,CAAC,OAAO,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,UAAU,MAAM,CAAkC,QAAgB,EAAE,cAAoC;IAC7G,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,IAAI,CAAC;YACJ,cAAc,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,QAAQ,CAAC,CAAU,CAAC,CAAC;QAC3B,CAAC;IACF,CAAC;IACD,IAAI,OAA2B,EAAE,SAA6B,CAAC;IAC/D,IAAI,CAAC,SAAS,GAAG,CAAC,QAAgB,EAAE,QAAgB,EAAE,EAAE;QACvD,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YAC/B,SAAS,GAAG,QAAQ,CAAC;QACtB,CAAC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,OAAO,GAAG,QAAQ,CAAC;QACpB,CAAC;IACF,CAAC,CAAC;IACF,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IAC7F,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC;AAC/B,CAAC","sourcesContent":["import { normalize } from 'path';\nimport type * as webpack from 'webpack';\nimport ts from 'typescript/lib/tsserverlibrary.js';\nimport { getConfigPath, getTransformers, scanDirective } from '../compiler/compiler.js';\n\nlet host: ts.CompilerHost;\nlet program: ts.Program;\nlet orgWriteFile: ts.WriteFileCallback;\nlet transformers: ts.CustomTransformers;\n\n/**\n * The entry point for ts-loader\n */\n\nexport function initTypeScript() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\tconsole.log(`can't parse command line `);\n\t\tthrow new Error('');\n\t}\n\thost = ts.createCompilerHost(cmd.options);\n\torgWriteFile = host.writeFile;\n\tprogram = ts.createProgram(cmd.fileNames, cmd.options, host);\n\ttransformers = getTransformers(program);\n\tscanDirective(program);\n}\n\nexport function loader(this: webpack.LoaderContext<{}>, contents: string, inputSourceMap?: Record<string, any>) {\n\tif (!program) {\n\t\ttry {\n\t\t\tinitTypeScript();\n\t\t} catch (e) {\n\t\t\tthis.callback(e as Error);\n\t\t}\n\t}\n\tlet content: string | undefined, sourceMap: string | undefined;\n\thost.writeFile = (fileName: string, contents: string) => {\n\t\tif (fileName.endsWith('.map')) {\n\t\t\tsourceMap = contents;\n\t\t} else if (fileName.endsWith('.js')) {\n\t\t\tcontent = contents;\n\t\t}\n\t};\n\tconst filePath = normalize(this.resourcePath);\n\tprogram.emit(program.getSourceFile(filePath), undefined, undefined, undefined, transformers);\n\tthis.callback(null, content, sourceMap);\n\thost.writeFile = orgWriteFile;\n}\n"]}
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/cli/webpack/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,OAAO,EAAE,MAAM,mCAAmC,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzF,IAAI,IAAqB,CAAC;AAC1B,IAAI,OAAmB,CAAC;AACxB,IAAI,YAAkC,CAAC;AACvC,IAAI,YAAmC,CAAC;AAExC;;GAEG;AAEH,MAAM,UAAU,cAAc;IAC7B,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,gCAAgC,CAAC,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,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IAC7F,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,GAAG,YAAY,CAAC;AAC/B,CAAC","sourcesContent":["import { normalize } from 'path';\nimport type * as webpack from 'webpack';\nimport ts from 'typescript/lib/tsserverlibrary.js';\nimport { getConfigPath, getTransformers, scanDirectives } from '../compiler/compiler.js';\n\nlet host: ts.CompilerHost;\nlet program: ts.Program;\nlet orgWriteFile: ts.WriteFileCallback;\nlet transformers: ts.CustomTransformers;\n\n/**\n * The entry point for ts-loader\n */\n\nexport function initTypeScript() {\n\tconst configPath = getConfigPath();\n\tconst cmd = ts.getParsedCommandLineOfConfigFile(configPath, {}, ts.sys as any);\n\tif (!cmd) {\n\t\tconsole.log(`can't parse command line `);\n\t\tthrow new Error('');\n\t}\n\thost = ts.createCompilerHost(cmd.options);\n\torgWriteFile = host.writeFile;\n\tprogram = ts.createProgram(cmd.fileNames, cmd.options, host);\n\ttransformers = getTransformers(program);\n\tscanDirectives(program);\n}\n\nexport function loader(this: webpack.LoaderContext<{}>, contents: string, inputSourceMap?: Record<string, any>) {\n\tif (!program) {\n\t\ttry {\n\t\t\tinitTypeScript();\n\t\t} catch (e) {\n\t\t\tthis.callback(e as Error);\n\t\t}\n\t}\n\tlet content: string | undefined, sourceMap: string | undefined;\n\thost.writeFile = (fileName: string, contents: string) => {\n\t\tif (fileName.endsWith('.map')) {\n\t\t\tsourceMap = contents;\n\t\t} else if (fileName.endsWith('.js')) {\n\t\t\tcontent = contents;\n\t\t}\n\t};\n\tconst filePath = normalize(this.resourcePath);\n\tprogram.emit(program.getSourceFile(filePath), undefined, undefined, undefined, transformers);\n\tthis.callback(null, content, sourceMap);\n\thost.writeFile = orgWriteFile;\n}\n"]}
@@ -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,KAAK,EAAE,CAAC;oBAC5E,MAAM,CACL,IAAI,EACJ,oEAAoE,CACpE,CAAC;gBACH,CAAC;gBACD,MAAM;YAEP,KAAK,EAAE,CAAC,UAAU,CAAC,WAAW;gBAC7B,MAAM,WAAW,GAAG,IAAsB,CAAC;gBAC3C,IAAI,WAAW,CAAC,aAAa,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;oBAC5D,MAAM,CAAC,WAAW,CAAC,aAAa,EAAE,gEAAgE,CAAC,CAAC;gBACrG,CAAC;gBACD,IACC,WAAW,CAAC,aAAa;oBACzB,WAAW,CAAC,aAAa,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,KAAK;oBACtD,WAAW,CAAC,aAA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AAC,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,CAAC;YACnB,CAAC;YAED,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;YAEvE,MAAM,eAAe,GAAe,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;YAClE,MAAM,gBAAgB,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC,IAAmB,EAAE,EAAE;gBACzE,OAAO,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,EAAE;oBAC5C,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAA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C9D,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,EAC1C,aAAa,EAAE,SAAS,EAAE,cAAc,EACxC,UAAU,EAAE,uBAAuB,EACnC,+BAA+B,GAC/B,MAAM,cAAc,CAAC;AAItB;;;;GAIG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAmB;IAChE,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAC7C,OAAO,CAAC,OAAiC,EAAiC,EAAE;QAC3E,OAAO,UAAU,CAAC,EAAE;YACnB,IAAI,eAAe,GAAG,KAAK,CAAC;YAC5B,IAAI,qBAA6B,CAAC;YAClC,IAAI,qBAA6B,CAAC;YAClC,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;gBAC/C,IAAI,EAAE,CAAC,mBAAmB,CA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UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;gBACzD,MAAM,UAAU,GAAG,gBAAgB,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBAC9D,UAAU,CAAC,IAAI,CAAC,2CAA2C,EAAE,CAAC,CAAC;gBAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;oBAC3D,OAAO,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;gBAC9D,CAAC,CAAC,CAAC;gBACH,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,uDAAuD;gBAC1E,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;gBAC/B,OAAO,EAAE,CAAC,OAAO,CAAC,gBAAgB,CACjC,UAAU,EACV,UAAU,EACV,gBAAgB,CAAC,iBAAiB,EAClC,gBAAgB,CAAC,uBAAuB,EACxC,gBAAgB,CAAC,eAAe,EAChC,gBAAgB,CAAC,eAAe,EAChC,gBAAgB,CAAC,sBAAsB,CACvC,CAAC;YACH,CAAC;YACD,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"]}