@ngtools/webpack 12.1.0-next.4 → 12.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +3 -3
- package/src/index.js +24 -2
- package/src/inline-data-loader.d.ts +1 -1
- package/src/inline-data-loader.js +1 -1
- package/src/ivy/host.js +21 -7
- package/src/ivy/loader.d.ts +4 -1
- package/src/ivy/loader.js +23 -7
- package/src/ivy/paths.js +20 -1
- package/src/ivy/plugin.d.ts +3 -1
- package/src/ivy/plugin.js +50 -18
- package/src/ivy/symbol.js +22 -24
- package/src/ivy/system.js +20 -1
- package/src/ivy/transformation.js +23 -4
- package/src/ngcc_processor.d.ts +3 -3
- package/src/ngcc_processor.js +25 -17
- package/src/paths-plugin.d.ts +1 -1
- package/src/paths-plugin.js +53 -24
- package/src/resource_loader.d.ts +1 -1
- package/src/resource_loader.js +30 -11
- package/src/transformers/elide_imports.d.ts +1 -2
- package/src/transformers/elide_imports.js +33 -13
- package/src/transformers/remove-ivy-jit-support-calls.js +23 -4
- package/src/transformers/replace_resources.d.ts +0 -1
- package/src/transformers/replace_resources.js +22 -62
- package/src/transformers/spec_helpers.js +22 -3
- package/src/webpack-diagnostics.d.ts +1 -1
- package/src/webpack-diagnostics.js +2 -3
- package/src/transformers/interfaces.d.ts +0 -34
- package/src/transformers/interfaces.js +0 -45
package/src/ngcc_processor.js
CHANGED
|
@@ -6,14 +6,32 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
9
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
29
|
exports.NgccProcessor = void 0;
|
|
11
30
|
const ngcc_1 = require("@angular/compiler-cli/ngcc");
|
|
12
31
|
const child_process_1 = require("child_process");
|
|
13
32
|
const crypto_1 = require("crypto");
|
|
14
|
-
const enhanced_resolve_1 = require("enhanced-resolve");
|
|
15
33
|
const fs_1 = require("fs");
|
|
16
|
-
const path = require("path");
|
|
34
|
+
const path = __importStar(require("path"));
|
|
17
35
|
const benchmark_1 = require("./benchmark");
|
|
18
36
|
// We cannot create a plugin for this, because NGTSC requires addition type
|
|
19
37
|
// information which ngcc creates when processing a package which was compiled with NGC.
|
|
@@ -23,25 +41,17 @@ const benchmark_1 = require("./benchmark");
|
|
|
23
41
|
// but could not be resolved to an NgModule class
|
|
24
42
|
// We now transform a package and it's typings when NGTSC is resolving a module.
|
|
25
43
|
class NgccProcessor {
|
|
26
|
-
constructor(propertiesToConsider, compilationWarnings, compilationErrors, basePath, tsConfigPath, inputFileSystem,
|
|
44
|
+
constructor(propertiesToConsider, compilationWarnings, compilationErrors, basePath, tsConfigPath, inputFileSystem, resolver) {
|
|
27
45
|
this.propertiesToConsider = propertiesToConsider;
|
|
28
46
|
this.compilationWarnings = compilationWarnings;
|
|
29
47
|
this.compilationErrors = compilationErrors;
|
|
30
48
|
this.basePath = basePath;
|
|
31
49
|
this.tsConfigPath = tsConfigPath;
|
|
32
50
|
this.inputFileSystem = inputFileSystem;
|
|
33
|
-
this.
|
|
51
|
+
this.resolver = resolver;
|
|
34
52
|
this._processedModules = new Set();
|
|
35
53
|
this._logger = new NgccLogger(this.compilationWarnings, this.compilationErrors);
|
|
36
54
|
this._nodeModulesDirectory = this.findNodeModulesDirectory(this.basePath);
|
|
37
|
-
this._resolver = enhanced_resolve_1.ResolverFactory.createResolver({
|
|
38
|
-
// NOTE: @types/webpack InputFileSystem is missing some methods
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
fileSystem: this.inputFileSystem,
|
|
41
|
-
extensions: ['.json'],
|
|
42
|
-
useSyncFileSystemCalls: true,
|
|
43
|
-
symlinks,
|
|
44
|
-
});
|
|
45
55
|
}
|
|
46
56
|
/** Process the entire node modules tree. */
|
|
47
57
|
process() {
|
|
@@ -144,6 +154,7 @@ class NgccProcessor {
|
|
|
144
154
|
}
|
|
145
155
|
/** Process a module and it's depedencies. */
|
|
146
156
|
processModule(moduleName, resolvedModule) {
|
|
157
|
+
var _a, _b;
|
|
147
158
|
const resolvedFileName = resolvedModule.resolvedFileName;
|
|
148
159
|
if (!resolvedFileName ||
|
|
149
160
|
moduleName.startsWith('.') ||
|
|
@@ -173,10 +184,7 @@ class NgccProcessor {
|
|
|
173
184
|
benchmark_1.timeEnd(timeLabel);
|
|
174
185
|
// Purge this file from cache, since NGCC add new mainFields. Ex: module_ivy_ngcc
|
|
175
186
|
// which are unknown in the cached file.
|
|
176
|
-
|
|
177
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
178
|
-
this.inputFileSystem.purge(packageJsonPath);
|
|
179
|
-
}
|
|
187
|
+
(_b = (_a = this.inputFileSystem).purge) === null || _b === void 0 ? void 0 : _b.call(_a, packageJsonPath);
|
|
180
188
|
this._processedModules.add(resolvedFileName);
|
|
181
189
|
}
|
|
182
190
|
invalidate(fileName) {
|
|
@@ -187,7 +195,7 @@ class NgccProcessor {
|
|
|
187
195
|
*/
|
|
188
196
|
tryResolvePackage(moduleName, resolvedFileName) {
|
|
189
197
|
try {
|
|
190
|
-
const resolvedPath = this.
|
|
198
|
+
const resolvedPath = this.resolver.resolveSync({}, resolvedFileName, `${moduleName}/package.json`);
|
|
191
199
|
return resolvedPath || undefined;
|
|
192
200
|
}
|
|
193
201
|
catch {
|
package/src/paths-plugin.d.ts
CHANGED
|
@@ -12,5 +12,5 @@ export declare class TypeScriptPathsPlugin {
|
|
|
12
12
|
private options?;
|
|
13
13
|
constructor(options?: TypeScriptPathsPluginOptions | undefined);
|
|
14
14
|
update(options: TypeScriptPathsPluginOptions): void;
|
|
15
|
-
apply(resolver:
|
|
15
|
+
apply(resolver: import('enhanced-resolve').Resolver): void;
|
|
16
16
|
}
|
package/src/paths-plugin.js
CHANGED
|
@@ -6,9 +6,28 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
9
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
29
|
exports.TypeScriptPathsPlugin = void 0;
|
|
11
|
-
const path = require("path");
|
|
30
|
+
const path = __importStar(require("path"));
|
|
12
31
|
const getInnerRequest = require('enhanced-resolve/lib/getInnerRequest');
|
|
13
32
|
class TypeScriptPathsPlugin {
|
|
14
33
|
constructor(options) {
|
|
@@ -20,55 +39,65 @@ class TypeScriptPathsPlugin {
|
|
|
20
39
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
21
40
|
apply(resolver) {
|
|
22
41
|
const target = resolver.ensureHook('resolve');
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (error) {
|
|
27
|
-
reject(error);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
resolve(result);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
resolver
|
|
36
|
-
.getHook('described-resolve')
|
|
37
|
-
.tapPromise('TypeScriptPathsPlugin', async (request, resolveContext) => {
|
|
42
|
+
resolver.getHook('described-resolve').tapAsync('TypeScriptPathsPlugin',
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
(request, resolveContext, callback) => {
|
|
38
45
|
if (!this.options) {
|
|
39
|
-
|
|
46
|
+
callback();
|
|
47
|
+
return;
|
|
40
48
|
}
|
|
41
49
|
if (!request || request.typescriptPathMapped) {
|
|
50
|
+
callback();
|
|
42
51
|
return;
|
|
43
52
|
}
|
|
44
53
|
const originalRequest = getInnerRequest(resolver, request);
|
|
45
54
|
if (!originalRequest) {
|
|
55
|
+
callback();
|
|
46
56
|
return;
|
|
47
57
|
}
|
|
48
58
|
// Only work on Javascript/TypeScript issuers.
|
|
49
59
|
if (!request.context.issuer || !request.context.issuer.match(/\.[jt]sx?$/)) {
|
|
60
|
+
callback();
|
|
50
61
|
return;
|
|
51
62
|
}
|
|
52
63
|
// Relative or absolute requests are not mapped
|
|
53
64
|
if (originalRequest.startsWith('.') || originalRequest.startsWith('/')) {
|
|
65
|
+
callback();
|
|
54
66
|
return;
|
|
55
67
|
}
|
|
56
68
|
// Ignore all webpack special requests
|
|
57
69
|
if (originalRequest.startsWith('!!')) {
|
|
70
|
+
callback();
|
|
58
71
|
return;
|
|
59
72
|
}
|
|
60
73
|
const replacements = findReplacements(originalRequest, this.options.paths || {});
|
|
61
|
-
|
|
74
|
+
const tryResolve = () => {
|
|
75
|
+
var _a;
|
|
76
|
+
const potential = replacements.shift();
|
|
77
|
+
if (!potential) {
|
|
78
|
+
callback();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
62
81
|
const potentialRequest = {
|
|
63
82
|
...request,
|
|
64
|
-
request: path.resolve(this.options.baseUrl || '', potential),
|
|
83
|
+
request: path.resolve(((_a = this.options) === null || _a === void 0 ? void 0 : _a.baseUrl) || '', potential),
|
|
65
84
|
typescriptPathMapped: true,
|
|
66
85
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
resolver.doResolve(target, potentialRequest, '', resolveContext,
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
(error, result) => {
|
|
89
|
+
if (error) {
|
|
90
|
+
callback(error);
|
|
91
|
+
}
|
|
92
|
+
else if (result) {
|
|
93
|
+
callback(undefined, result);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
tryResolve();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
tryResolve();
|
|
72
101
|
});
|
|
73
102
|
}
|
|
74
103
|
}
|
package/src/resource_loader.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import { Compilation } from 'webpack';
|
|
8
|
+
import type { Compilation } from 'webpack';
|
|
9
9
|
export declare class WebpackResourceLoader {
|
|
10
10
|
private _parentCompilation?;
|
|
11
11
|
private _fileDependencies;
|
package/src/resource_loader.js
CHANGED
|
@@ -6,12 +6,30 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
9
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
29
|
exports.WebpackResourceLoader = void 0;
|
|
11
30
|
const crypto_1 = require("crypto");
|
|
12
|
-
const path = require("path");
|
|
13
|
-
const vm = require("vm");
|
|
14
|
-
const webpack_1 = require("webpack");
|
|
31
|
+
const path = __importStar(require("path"));
|
|
32
|
+
const vm = __importStar(require("vm"));
|
|
15
33
|
const inline_data_loader_1 = require("./inline-data-loader");
|
|
16
34
|
const paths_1 = require("./ivy/paths");
|
|
17
35
|
class WebpackResourceLoader {
|
|
@@ -97,12 +115,13 @@ class WebpackResourceLoader {
|
|
|
97
115
|
name: 'resource',
|
|
98
116
|
},
|
|
99
117
|
};
|
|
100
|
-
const context = this._parentCompilation.compiler
|
|
118
|
+
const { context, webpack } = this._parentCompilation.compiler;
|
|
119
|
+
const { EntryPlugin, NormalModule, library, node, sources } = webpack;
|
|
101
120
|
const childCompiler = this._parentCompilation.createChildCompiler('angular-compiler:resource', outputOptions, [
|
|
102
|
-
new
|
|
103
|
-
new
|
|
104
|
-
new
|
|
105
|
-
new
|
|
121
|
+
new node.NodeTemplatePlugin(outputOptions),
|
|
122
|
+
new node.NodeTargetPlugin(),
|
|
123
|
+
new EntryPlugin(context, entry, { name: 'resource' }),
|
|
124
|
+
new library.EnableLibraryPlugin('var'),
|
|
106
125
|
]);
|
|
107
126
|
childCompiler.hooks.thisCompilation.tap('angular-compiler', (compilation, { normalModuleFactory }) => {
|
|
108
127
|
// If no data is provided, the resource will be read from the filesystem
|
|
@@ -119,7 +138,7 @@ class WebpackResourceLoader {
|
|
|
119
138
|
}
|
|
120
139
|
return true;
|
|
121
140
|
});
|
|
122
|
-
|
|
141
|
+
NormalModule.getCompilationHooks(compilation)
|
|
123
142
|
.readResourceForScheme.for('angular-resource')
|
|
124
143
|
.tap('angular-compiler', () => data);
|
|
125
144
|
compilation[inline_data_loader_1.InlineAngularResourceSymbol] = data;
|
|
@@ -132,7 +151,7 @@ class WebpackResourceLoader {
|
|
|
132
151
|
try {
|
|
133
152
|
const output = this._evaluate(outputFilePath, asset.source().toString());
|
|
134
153
|
if (typeof output === 'string') {
|
|
135
|
-
compilation.assets[outputFilePath] = new
|
|
154
|
+
compilation.assets[outputFilePath] = new sources.RawSource(output);
|
|
136
155
|
}
|
|
137
156
|
}
|
|
138
157
|
catch (error) {
|
|
@@ -144,7 +163,7 @@ class WebpackResourceLoader {
|
|
|
144
163
|
let finalContent;
|
|
145
164
|
let finalMap;
|
|
146
165
|
childCompiler.hooks.compilation.tap('angular-compiler', (childCompilation) => {
|
|
147
|
-
childCompilation.hooks.processAssets.tap({ name: 'angular-compiler', stage:
|
|
166
|
+
childCompilation.hooks.processAssets.tap({ name: 'angular-compiler', stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT }, () => {
|
|
148
167
|
var _a, _b;
|
|
149
168
|
finalContent = (_a = childCompilation.assets[outputFilePath]) === null || _a === void 0 ? void 0 : _a.source().toString();
|
|
150
169
|
finalMap = (_b = childCompilation.assets[outputFilePath + '.map']) === null || _b === void 0 ? void 0 : _b.source().toString();
|
|
@@ -6,5 +6,4 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
8
|
import * as ts from 'typescript';
|
|
9
|
-
|
|
10
|
-
export declare function elideImports(sourceFile: ts.SourceFile, removedNodes: ts.Node[], getTypeChecker: () => ts.TypeChecker, compilerOptions: ts.CompilerOptions): TransformOperation[];
|
|
9
|
+
export declare function elideImports(sourceFile: ts.SourceFile, removedNodes: ts.Node[], getTypeChecker: () => ts.TypeChecker, compilerOptions: ts.CompilerOptions): Set<ts.Node>;
|
|
@@ -6,10 +6,28 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
9
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
29
|
exports.elideImports = void 0;
|
|
11
|
-
const ts = require("typescript");
|
|
12
|
-
const interfaces_1 = require("./interfaces");
|
|
30
|
+
const ts = __importStar(require("typescript"));
|
|
13
31
|
// Remove imports for which all identifiers have been removed.
|
|
14
32
|
// Needs type checker, and works even if it's not the first transformer.
|
|
15
33
|
// Works by removing imports for symbols whose identifiers have all been removed.
|
|
@@ -17,9 +35,9 @@ const interfaces_1 = require("./interfaces");
|
|
|
17
35
|
// but the type checker doesn't know.
|
|
18
36
|
// See https://github.com/Microsoft/TypeScript/issues/17552 for more information.
|
|
19
37
|
function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions) {
|
|
20
|
-
const
|
|
38
|
+
const importNodeRemovals = new Set();
|
|
21
39
|
if (removedNodes.length === 0) {
|
|
22
|
-
return
|
|
40
|
+
return importNodeRemovals;
|
|
23
41
|
}
|
|
24
42
|
const typeChecker = getTypeChecker();
|
|
25
43
|
// Collect all imports and used identifiers
|
|
@@ -100,7 +118,7 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
100
118
|
ts.forEachChild(node, visit);
|
|
101
119
|
});
|
|
102
120
|
if (imports.length === 0) {
|
|
103
|
-
return
|
|
121
|
+
return importNodeRemovals;
|
|
104
122
|
}
|
|
105
123
|
const isUnused = (node) => {
|
|
106
124
|
// Do not remove JSX factory imports
|
|
@@ -119,11 +137,11 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
119
137
|
if (namedBindings && ts.isNamespaceImport(namedBindings)) {
|
|
120
138
|
// "import * as XYZ from 'abc';"
|
|
121
139
|
if (isUnused(namedBindings.name)) {
|
|
122
|
-
|
|
140
|
+
importNodeRemovals.add(node);
|
|
123
141
|
}
|
|
124
142
|
}
|
|
125
143
|
else {
|
|
126
|
-
const
|
|
144
|
+
const specifierNodeRemovals = [];
|
|
127
145
|
let clausesCount = 0;
|
|
128
146
|
// "import { XYZ, ... } from 'abc';"
|
|
129
147
|
if (namedBindings && ts.isNamedImports(namedBindings)) {
|
|
@@ -134,7 +152,7 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
134
152
|
removedClausesCount++;
|
|
135
153
|
// in case we don't have any more namedImports we should remove the parent ie the {}
|
|
136
154
|
const nodeToRemove = clausesCount === removedClausesCount ? specifier.parent : specifier;
|
|
137
|
-
|
|
155
|
+
specifierNodeRemovals.push(nodeToRemove);
|
|
138
156
|
}
|
|
139
157
|
}
|
|
140
158
|
}
|
|
@@ -142,17 +160,19 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
142
160
|
if (node.importClause.name) {
|
|
143
161
|
clausesCount++;
|
|
144
162
|
if (isUnused(node.importClause.name)) {
|
|
145
|
-
|
|
163
|
+
specifierNodeRemovals.push(node.importClause.name);
|
|
146
164
|
}
|
|
147
165
|
}
|
|
148
|
-
if (
|
|
149
|
-
|
|
166
|
+
if (specifierNodeRemovals.length === clausesCount) {
|
|
167
|
+
importNodeRemovals.add(node);
|
|
150
168
|
}
|
|
151
169
|
else {
|
|
152
|
-
|
|
170
|
+
for (const specifierNodeRemoval of specifierNodeRemovals) {
|
|
171
|
+
importNodeRemovals.add(specifierNodeRemoval);
|
|
172
|
+
}
|
|
153
173
|
}
|
|
154
174
|
}
|
|
155
175
|
}
|
|
156
|
-
return
|
|
176
|
+
return importNodeRemovals;
|
|
157
177
|
}
|
|
158
178
|
exports.elideImports = elideImports;
|
|
@@ -6,9 +6,28 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
9
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
29
|
exports.removeIvyJitSupportCalls = void 0;
|
|
11
|
-
const ts = require("typescript");
|
|
30
|
+
const ts = __importStar(require("typescript"));
|
|
12
31
|
const elide_imports_1 = require("./elide_imports");
|
|
13
32
|
function removeIvyJitSupportCalls(classMetadata, ngModuleScope, getTypeChecker) {
|
|
14
33
|
return (context) => {
|
|
@@ -38,10 +57,10 @@ function removeIvyJitSupportCalls(classMetadata, ngModuleScope, getTypeChecker)
|
|
|
38
57
|
let updatedSourceFile = ts.visitEachChild(sourceFile, visitNode, context);
|
|
39
58
|
if (removedNodes.length > 0) {
|
|
40
59
|
// Remove any unused imports
|
|
41
|
-
const importRemovals = elide_imports_1.elideImports(updatedSourceFile, removedNodes, getTypeChecker, context.getCompilerOptions())
|
|
42
|
-
if (importRemovals.
|
|
60
|
+
const importRemovals = elide_imports_1.elideImports(updatedSourceFile, removedNodes, getTypeChecker, context.getCompilerOptions());
|
|
61
|
+
if (importRemovals.size > 0) {
|
|
43
62
|
updatedSourceFile = ts.visitEachChild(updatedSourceFile, function visitForRemoval(node) {
|
|
44
|
-
return importRemovals.
|
|
63
|
+
return importRemovals.has(node)
|
|
45
64
|
? undefined
|
|
46
65
|
: ts.visitEachChild(node, visitForRemoval, context);
|
|
47
66
|
}, context);
|
|
@@ -8,4 +8,3 @@
|
|
|
8
8
|
import * as ts from 'typescript';
|
|
9
9
|
export declare function replaceResources(shouldTransform: (fileName: string) => boolean, getTypeChecker: () => ts.TypeChecker, directTemplateLoading?: boolean, inlineStyleMimeType?: string, inlineStyleFileExtension?: string): ts.TransformerFactory<ts.SourceFile>;
|
|
10
10
|
export declare function getResourceUrl(node: ts.Node, loader?: string): string | null;
|
|
11
|
-
export declare function workaroundStylePreprocessing(sourceFile: ts.SourceFile): void;
|
|
@@ -6,9 +6,28 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
9
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
11
|
-
const ts = require("typescript");
|
|
29
|
+
exports.getResourceUrl = exports.replaceResources = void 0;
|
|
30
|
+
const ts = __importStar(require("typescript"));
|
|
12
31
|
const inlineDataLoaderPath = require.resolve('../inline-data-loader');
|
|
13
32
|
function replaceResources(shouldTransform, getTypeChecker, directTemplateLoading = false, inlineStyleMimeType, inlineStyleFileExtension) {
|
|
14
33
|
if (inlineStyleMimeType && !/^text\/[-.\w]+$/.test(inlineStyleMimeType)) {
|
|
@@ -108,7 +127,7 @@ function visitComponentMetadata(nodeFactory, node, styleReplacements, directTemp
|
|
|
108
127
|
else if (inlineStyleFileExtension) {
|
|
109
128
|
const data = Buffer.from(node.text).toString('base64');
|
|
110
129
|
const containingFile = node.getSourceFile().fileName;
|
|
111
|
-
url = `${containingFile}.${inlineStyleFileExtension}!=!${inlineDataLoaderPath}?data=${data}!${containingFile}`;
|
|
130
|
+
url = `${containingFile}.${inlineStyleFileExtension}!=!${inlineDataLoaderPath}?data=${encodeURIComponent(data)}!${containingFile}`;
|
|
112
131
|
}
|
|
113
132
|
else {
|
|
114
133
|
return nodeFactory.createStringLiteral(node.text);
|
|
@@ -203,62 +222,3 @@ function getDecoratorOrigin(decorator, typeChecker) {
|
|
|
203
222
|
}
|
|
204
223
|
return null;
|
|
205
224
|
}
|
|
206
|
-
function workaroundStylePreprocessing(sourceFile) {
|
|
207
|
-
const visitNode = (node) => {
|
|
208
|
-
var _a;
|
|
209
|
-
if (ts.isClassDeclaration(node) && ((_a = node.decorators) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
210
|
-
for (const decorator of node.decorators) {
|
|
211
|
-
visitDecoratorWorkaround(decorator);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return ts.forEachChild(node, visitNode);
|
|
215
|
-
};
|
|
216
|
-
ts.forEachChild(sourceFile, visitNode);
|
|
217
|
-
}
|
|
218
|
-
exports.workaroundStylePreprocessing = workaroundStylePreprocessing;
|
|
219
|
-
function visitDecoratorWorkaround(node) {
|
|
220
|
-
if (!ts.isCallExpression(node.expression)) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const decoratorFactory = node.expression;
|
|
224
|
-
if (!ts.isIdentifier(decoratorFactory.expression) ||
|
|
225
|
-
decoratorFactory.expression.text !== 'Component') {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const args = decoratorFactory.arguments;
|
|
229
|
-
if (args.length !== 1 || !ts.isObjectLiteralExpression(args[0])) {
|
|
230
|
-
// Unsupported component metadata
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
const objectExpression = args[0];
|
|
234
|
-
// check if a `styles` property is present
|
|
235
|
-
let hasStyles = false;
|
|
236
|
-
for (const element of objectExpression.properties) {
|
|
237
|
-
if (!ts.isPropertyAssignment(element) || ts.isComputedPropertyName(element.name)) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
if (element.name.text === 'styles') {
|
|
241
|
-
hasStyles = true;
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (hasStyles) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
const nodeFactory = ts.factory;
|
|
249
|
-
// add a `styles` property to workaround upstream compiler defect
|
|
250
|
-
const emptyArray = nodeFactory.createArrayLiteralExpression();
|
|
251
|
-
const stylePropertyName = nodeFactory.createIdentifier('styles');
|
|
252
|
-
const styleProperty = nodeFactory.createPropertyAssignment(stylePropertyName, emptyArray);
|
|
253
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
254
|
-
stylePropertyName.parent = styleProperty;
|
|
255
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
256
|
-
emptyArray.parent = styleProperty;
|
|
257
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
258
|
-
styleProperty.parent = objectExpression;
|
|
259
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
260
|
-
objectExpression.properties = nodeFactory.createNodeArray([
|
|
261
|
-
...objectExpression.properties,
|
|
262
|
-
styleProperty,
|
|
263
|
-
]);
|
|
264
|
-
}
|
|
@@ -6,10 +6,29 @@
|
|
|
6
6
|
* Use of this source code is governed by an MIT-style license that can be
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod;
|
|
23
|
+
var result = {};
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
+
__setModuleDefault(result, mod);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
9
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
29
|
exports.transformTypescript = exports.createTypescriptContext = void 0;
|
|
11
30
|
const path_1 = require("path");
|
|
12
|
-
const ts = require("typescript");
|
|
31
|
+
const ts = __importStar(require("typescript"));
|
|
13
32
|
// Test transform helpers.
|
|
14
33
|
const basefileName = 'test-file.ts';
|
|
15
34
|
function createTypescriptContext(content, additionalFiles, useLibs = false, extraCompilerOptions = {}, jsxFile = false) {
|
|
@@ -20,8 +39,8 @@ function createTypescriptContext(content, additionalFiles, useLibs = false, extr
|
|
|
20
39
|
allowJs: true,
|
|
21
40
|
newLine: ts.NewLineKind.LineFeed,
|
|
22
41
|
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
23
|
-
module: ts.ModuleKind.
|
|
24
|
-
target: ts.ScriptTarget.
|
|
42
|
+
module: ts.ModuleKind.ES2020,
|
|
43
|
+
target: ts.ScriptTarget.ES2020,
|
|
25
44
|
skipLibCheck: true,
|
|
26
45
|
sourceMap: false,
|
|
27
46
|
importHelpers: true,
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://angular.io/license
|
|
7
7
|
*/
|
|
8
|
-
import { Compilation } from 'webpack';
|
|
8
|
+
import type { Compilation } from 'webpack';
|
|
9
9
|
export declare function addWarning(compilation: Compilation, message: string): void;
|
|
10
10
|
export declare function addError(compilation: Compilation, message: string): void;
|
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.addError = exports.addWarning = void 0;
|
|
11
|
-
const webpack_1 = require("webpack");
|
|
12
11
|
function addWarning(compilation, message) {
|
|
13
|
-
compilation.warnings.push(new
|
|
12
|
+
compilation.warnings.push(new compilation.compiler.webpack.WebpackError(message));
|
|
14
13
|
}
|
|
15
14
|
exports.addWarning = addWarning;
|
|
16
15
|
function addError(compilation, message) {
|
|
17
|
-
compilation.errors.push(new
|
|
16
|
+
compilation.errors.push(new compilation.compiler.webpack.WebpackError(message));
|
|
18
17
|
}
|
|
19
18
|
exports.addError = addError;
|