@analogjs/vite-plugin-angular 3.0.0-beta.6 → 3.0.0-beta.61
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/migrations/migrate-setup-vitest/migrate-setup-vitest.js +3 -3
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
- package/ngp/LICENSE +21 -0
- package/ngp/api.mjs +46806 -0
- package/ngp/build.json +4 -0
- package/ngp/ng_analyze.cjs +601 -0
- package/ngp/ng_analyze_bg.wasm +0 -0
- package/package.json +5 -2
- package/src/index.d.ts +2 -0
- package/src/index.js +4 -3
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.js +2 -3
- package/src/lib/angular-build-context.d.ts +215 -0
- package/src/lib/angular-build-context.js +360 -0
- package/src/lib/angular-build-context.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
- package/src/lib/angular-build-optimizer-plugin.js +25 -11
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +5 -3
- package/src/lib/angular-jit-plugin.js +16 -9
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +6 -109
- package/src/lib/angular-vite-plugin.js +9 -1251
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +3 -2
- package/src/lib/angular-vitest-plugin.js +7 -5
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/companion-plugins.d.ts +7 -0
- package/src/lib/companion-plugins.js +37 -0
- package/src/lib/companion-plugins.js.map +1 -0
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
- package/src/lib/compilation-api/compilation-api-plugin.js +156 -285
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/compilation-api/index.js +1 -2
- package/src/lib/compiler/angular-version.js +0 -1
- package/src/lib/compiler/class-field-lowering.js +1 -2
- package/src/lib/compiler/compile.d.ts +1 -1
- package/src/lib/compiler/compile.js +224 -151
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/constants.js +1 -2
- package/src/lib/compiler/debug.js +1 -2
- package/src/lib/compiler/defer.d.ts +2 -3
- package/src/lib/compiler/defer.js +13 -16
- package/src/lib/compiler/defer.js.map +1 -1
- package/src/lib/compiler/dts-reader.d.ts +6 -1
- package/src/lib/compiler/dts-reader.js +20 -12
- package/src/lib/compiler/dts-reader.js.map +1 -1
- package/src/lib/compiler/hmr.d.ts +4 -0
- package/src/lib/compiler/hmr.js +8 -4
- package/src/lib/compiler/hmr.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -2
- package/src/lib/compiler/index.js +6 -6
- package/src/lib/compiler/jit-metadata.js +1 -2
- package/src/lib/compiler/jit-transform.js +37 -15
- package/src/lib/compiler/jit-transform.js.map +1 -1
- package/src/lib/compiler/js-emitter.d.ts +0 -3
- package/src/lib/compiler/js-emitter.js +4 -23
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/metadata.js +2 -3
- package/src/lib/compiler/registry.d.ts +7 -1
- package/src/lib/compiler/registry.js +24 -5
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/compiler/resource-inliner.d.ts +8 -9
- package/src/lib/compiler/resource-inliner.js +11 -20
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.d.ts +22 -1
- package/src/lib/compiler/style-ast.js +37 -20
- package/src/lib/compiler/style-ast.js.map +1 -1
- package/src/lib/compiler/type-elision.d.ts +4 -3
- package/src/lib/compiler/type-elision.js +11 -13
- package/src/lib/compiler/type-elision.js.map +1 -1
- package/src/lib/compiler/utils.d.ts +9 -7
- package/src/lib/compiler/utils.js +50 -11
- package/src/lib/compiler/utils.js.map +1 -1
- package/src/lib/compiler-plugin.js +1 -2
- package/src/lib/component-resolvers.js +1 -2
- package/src/lib/component-scanner.d.ts +74 -0
- package/src/lib/component-scanner.js +177 -0
- package/src/lib/component-scanner.js.map +1 -0
- package/src/lib/component-styles-plugin.d.ts +52 -0
- package/src/lib/component-styles-plugin.js +352 -0
- package/src/lib/component-styles-plugin.js.map +1 -0
- package/src/lib/compose-angular-plugins.d.ts +12 -0
- package/src/lib/compose-angular-plugins.js +30 -0
- package/src/lib/compose-angular-plugins.js.map +1 -0
- package/src/lib/dev-server-mode-plugin.d.ts +7 -0
- package/src/lib/dev-server-mode-plugin.js +22 -0
- package/src/lib/dev-server-mode-plugin.js.map +1 -0
- package/src/lib/encapsulation-plugin.js +1 -2
- package/src/lib/fast-compile-api.d.ts +62 -0
- package/src/lib/fast-compile-api.js +11 -0
- package/src/lib/fast-compile-api.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +6 -1
- package/src/lib/fast-compile-plugin.js +169 -110
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.d.ts +3 -0
- package/src/lib/host.js +5 -4
- package/src/lib/host.js.map +1 -1
- package/src/lib/hot-update-batch.js +1 -2
- package/src/lib/live-reload-plugin.d.ts +6 -3
- package/src/lib/live-reload-plugin.js +14 -8
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/ngp-compile-api.d.ts +55 -0
- package/src/lib/ngp-compile-api.js +11 -0
- package/src/lib/ngp-compile-api.js.map +1 -0
- package/src/lib/ngp-compile-plugin.d.ts +4 -0
- package/src/lib/ngp-compile-plugin.js +672 -0
- package/src/lib/ngp-compile-plugin.js.map +1 -0
- package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
- package/src/lib/ngtsc-compile-plugin.js +776 -0
- package/src/lib/ngtsc-compile-plugin.js.map +1 -0
- package/src/lib/nx-folder-plugin.d.ts +6 -5
- package/src/lib/nx-folder-plugin.js +13 -9
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
- package/src/lib/plugins/file-replacements.plugin.js +2 -2
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +5 -1
- package/src/lib/router-plugin.js +14 -6
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-preprocessor.js +1 -2
- package/src/lib/stylesheet-registry.js +1 -2
- package/src/lib/stylesheet-registry.js.map +1 -1
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -3
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +1 -2
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/utils/compilation-shared.js +3 -4
- package/src/lib/utils/css-extension-resolver.js +1 -2
- package/src/lib/utils/css-preprocessor-workers.js +1 -2
- package/src/lib/utils/debug-harness.js +1 -2
- package/src/lib/utils/debug-log-file.js +1 -2
- package/src/lib/utils/debug.js +1 -2
- package/src/lib/utils/devkit.js +2 -3
- package/src/lib/utils/hmr-component-updates.d.ts +7 -0
- package/src/lib/utils/hmr-component-updates.js +86 -0
- package/src/lib/utils/hmr-component-updates.js.map +1 -0
- package/src/lib/utils/jit-inline-styles.js +1 -2
- package/src/lib/utils/lsp-type-checker.d.ts +75 -0
- package/src/lib/utils/lsp-type-checker.js +532 -0
- package/src/lib/utils/lsp-type-checker.js.map +1 -0
- package/src/lib/utils/ngp-host-fs.d.ts +43 -0
- package/src/lib/utils/ngp-host-fs.js +128 -0
- package/src/lib/utils/ngp-host-fs.js.map +1 -0
- package/src/lib/utils/plugin-config.d.ts +15 -8
- package/src/lib/utils/plugin-config.js +19 -7
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/rolldown.js +1 -2
- package/src/lib/utils/safe-module-paths.js +1 -2
- package/src/lib/utils/stylesheet-warning.d.ts +2 -0
- package/src/lib/utils/stylesheet-warning.js +10 -0
- package/src/lib/utils/stylesheet-warning.js.map +1 -0
- package/src/lib/utils/transform-cache.js +1 -2
- package/src/lib/utils/transform-cache.js.map +1 -1
- package/src/lib/utils/tsconfig-resolver.js +2 -3
- package/src/lib/utils/virtual-ids.js +1 -2
- package/src/lib/utils/virtual-resources.js +1 -2
- package/src/lib/utils/virtual-resources.js.map +1 -1
- package/src/lib/virtual-modules-plugin.d.ts +11 -3
- package/src/lib/virtual-modules-plugin.js +70 -15
- package/src/lib/virtual-modules-plugin.js.map +1 -1
|
@@ -1,23 +1,63 @@
|
|
|
1
|
+
import { findAllClasses, parseOxc, resolveSyntheticImportSpecifier, walkOxc } from "./utils.js";
|
|
1
2
|
import { ANGULAR_DECORATORS, FIELD_DECORATORS } from "./constants.js";
|
|
2
|
-
import { findAllClasses, resolveSyntheticImportSpecifier } from "./utils.js";
|
|
3
3
|
import { angularVersionAtLeast } from "./angular-version.js";
|
|
4
4
|
import { detectTypeOnlyImportNames, elideTypeOnlyImportsMagicString } from "./type-elision.js";
|
|
5
|
-
import { emitAngularExpr, emitAngularStmt, setEmitterSourceCode
|
|
5
|
+
import { emitAngularExpr, emitAngularStmt, setEmitterSourceCode } from "./js-emitter.js";
|
|
6
6
|
import { lowerClassFields } from "./class-field-lowering.js";
|
|
7
7
|
import { collectStringConstants, detectFieldDecorators, detectSignals, extractConstructorDeps, extractMetadata } from "./metadata.js";
|
|
8
|
-
import { buildDeferDependencyMap } from "./defer.js";
|
|
8
|
+
import { buildDeferDependencyMap, buildImportMap } from "./defer.js";
|
|
9
9
|
import { buildCtorParameters, buildPropDecorators } from "./jit-metadata.js";
|
|
10
10
|
import { debugCompile } from "./debug.js";
|
|
11
|
+
import { getPropertyKey, inlineStyleRanges } from "./style-ast.js";
|
|
11
12
|
import * as fs from "node:fs";
|
|
12
13
|
import * as path$1 from "node:path";
|
|
13
14
|
import * as o from "@angular/compiler";
|
|
14
|
-
import { ConstantPool, FactoryTarget, ParseLocation, ParseSourceFile, ParseSourceSpan, R3NgModuleMetadataKind, R3SelectorScopeMode, compileClassMetadata, compileComponentFromMetadata, compileDeclareClassMetadata, compileDeclareComponentFromMetadata, compileDeclareDirectiveFromMetadata, compileDeclareFactoryFunction, compileDeclareInjectableFromMetadata, compileDeclareInjectorFromMetadata, compileDeclareNgModuleFromMetadata, compileDeclarePipeFromMetadata, compileDirectiveFromMetadata, compileFactoryFunction, compileInjector, compileNgModule, compilePipeFromMetadata, makeBindingParser, parseHostBindings, parseTemplate } from "@angular/compiler";
|
|
15
|
-
import { parseSync } from "oxc-parser";
|
|
16
|
-
import * as ts from "typescript";
|
|
15
|
+
import { ConstantPool, FactoryTarget, ParseLocation, ParseSourceFile, ParseSourceSpan, R3NgModuleMetadataKind, R3SelectorScopeMode, compileClassMetadata, compileComponentClassMetadata, compileComponentFromMetadata, compileDeclareClassMetadata, compileDeclareComponentFromMetadata, compileDeclareDirectiveFromMetadata, compileDeclareFactoryFunction, compileDeclareInjectableFromMetadata, compileDeclareInjectorFromMetadata, compileDeclareNgModuleFromMetadata, compileDeclarePipeFromMetadata, compileDirectiveFromMetadata, compileFactoryFunction, compileInjector, compileNgModule, compilePipeFromMetadata, makeBindingParser, parseHostBindings, parseTemplate } from "@angular/compiler";
|
|
17
16
|
import MagicString from "magic-string";
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
|
|
17
|
+
// packages/vite-plugin-angular/src/lib/compiler/compile.ts
|
|
18
|
+
function toTopLevelStatement(stmt) {
|
|
19
|
+
const isExport = (stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration") && stmt.declaration;
|
|
20
|
+
const decl = isExport ? stmt.declaration : stmt;
|
|
21
|
+
return {
|
|
22
|
+
decl,
|
|
23
|
+
exported: !!isExport,
|
|
24
|
+
start: Math.min(stmt.start, decl.decorators?.[0]?.start ?? stmt.start),
|
|
25
|
+
end: stmt.end
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Get the callee name of a decorator call, e.g. `Component` for `@Component(...)`. */
|
|
29
|
+
function decoratorCallName(dec, sourceCode) {
|
|
30
|
+
const callee = dec.expression;
|
|
31
|
+
if (callee?.type !== "CallExpression") return void 0;
|
|
32
|
+
return sourceCode.slice(callee.callee.start, callee.callee.end);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Pair each inline style of a component with its processed CSS, skipping the
|
|
36
|
+
* ones whose processing failed.
|
|
37
|
+
*/
|
|
38
|
+
function resolveInlineStyles(range, resolvedInlineStyles) {
|
|
39
|
+
if (!range || !resolvedInlineStyles) return [];
|
|
40
|
+
return range.styles.flatMap((style, k) => {
|
|
41
|
+
const css = resolvedInlineStyles.get(range.start + k);
|
|
42
|
+
return css === void 0 ? [] : [{
|
|
43
|
+
...style,
|
|
44
|
+
css
|
|
45
|
+
}];
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Source text of a `styles` value with each resolved inline style replaced by
|
|
50
|
+
* its processed CSS, so the class metadata a TestBed override recompiles from
|
|
51
|
+
* carries the same styles as ɵcmp.
|
|
52
|
+
*/
|
|
53
|
+
function withResolvedInlineStyles(stylesNode, styles, sourceCode) {
|
|
54
|
+
let text = "";
|
|
55
|
+
let pos = stylesNode.start;
|
|
56
|
+
for (const { node, css } of styles) {
|
|
57
|
+
text += sourceCode.slice(pos, node.start) + JSON.stringify(css);
|
|
58
|
+
pos = node.end;
|
|
59
|
+
}
|
|
60
|
+
return text + sourceCode.slice(pos, stylesNode.end);
|
|
21
61
|
}
|
|
22
62
|
/**
|
|
23
63
|
* Normalize a `providers` / `viewProviders` metadata value into the single
|
|
@@ -35,37 +75,59 @@ function providersToExpr(value) {
|
|
|
35
75
|
if (Array.isArray(value)) return value.length ? new o.LiteralArrayExpr(value) : null;
|
|
36
76
|
return value;
|
|
37
77
|
}
|
|
78
|
+
var LAZY_SCOPE_TYPES = /* @__PURE__ */ new Set([
|
|
79
|
+
"FunctionDeclaration",
|
|
80
|
+
"FunctionExpression",
|
|
81
|
+
"ArrowFunctionExpression",
|
|
82
|
+
"ClassDeclaration",
|
|
83
|
+
"ClassExpression",
|
|
84
|
+
"TSFunctionType",
|
|
85
|
+
"TSConstructorType",
|
|
86
|
+
"TSMethodSignature",
|
|
87
|
+
"TSCallSignatureDeclaration",
|
|
88
|
+
"TSConstructSignatureDeclaration"
|
|
89
|
+
]);
|
|
38
90
|
/**
|
|
39
91
|
* Collect identifier names referenced in eagerly-evaluated code only.
|
|
40
92
|
* Skips function/arrow/class bodies so that lazy references
|
|
41
93
|
* (e.g. `const TOKEN = () => LaterClass`) are not treated as dependencies.
|
|
94
|
+
* The root node's own children are always walked.
|
|
42
95
|
*/
|
|
43
|
-
function collectIdentifiers(
|
|
96
|
+
function collectIdentifiers(root) {
|
|
44
97
|
const ids = /* @__PURE__ */ new Set();
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
ts.forEachChild(node, walk);
|
|
98
|
+
walkOxc(root, (n) => {
|
|
99
|
+
if (n.type === "Identifier") ids.add(n.name);
|
|
100
|
+
return n === root || !LAZY_SCOPE_TYPES.has(n.type);
|
|
101
|
+
});
|
|
51
102
|
return ids;
|
|
52
103
|
}
|
|
53
|
-
/** Extract the names defined by a top-level
|
|
54
|
-
function getDefinedNames(
|
|
55
|
-
if (
|
|
104
|
+
/** Extract the names defined by a top-level declaration. */
|
|
105
|
+
function getDefinedNames(decl) {
|
|
106
|
+
if (decl.type === "VariableDeclaration") {
|
|
56
107
|
const names = [];
|
|
57
|
-
for (const
|
|
108
|
+
for (const d of decl.declarations) collectBindingNames(d.id, names);
|
|
58
109
|
return names;
|
|
59
110
|
}
|
|
60
|
-
if (
|
|
61
|
-
if (ts.isClassDeclaration(stmt) && stmt.name) return [stmt.name.text];
|
|
111
|
+
if ((decl.type === "FunctionDeclaration" || decl.type === "ClassDeclaration") && decl.id) return [decl.id.name];
|
|
62
112
|
return [];
|
|
63
113
|
}
|
|
64
|
-
/** Recursively collect all bound identifiers from a binding
|
|
65
|
-
function collectBindingNames(
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
114
|
+
/** Recursively collect all bound identifiers from a binding pattern. */
|
|
115
|
+
function collectBindingNames(pattern, out) {
|
|
116
|
+
if (!pattern) return;
|
|
117
|
+
switch (pattern.type) {
|
|
118
|
+
case "Identifier":
|
|
119
|
+
out.push(pattern.name);
|
|
120
|
+
break;
|
|
121
|
+
case "ObjectPattern":
|
|
122
|
+
for (const prop of pattern.properties) collectBindingNames(prop.type === "RestElement" ? prop.argument : prop.value, out);
|
|
123
|
+
break;
|
|
124
|
+
case "ArrayPattern":
|
|
125
|
+
for (const el of pattern.elements) collectBindingNames(el, out);
|
|
126
|
+
break;
|
|
127
|
+
case "RestElement":
|
|
128
|
+
collectBindingNames(pattern.argument, out);
|
|
129
|
+
break;
|
|
130
|
+
case "AssignmentPattern": collectBindingNames(pattern.left, out);
|
|
69
131
|
}
|
|
70
132
|
}
|
|
71
133
|
function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
@@ -77,8 +139,8 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
77
139
|
const isPartial = opts.compilationMode === "partial";
|
|
78
140
|
const startTimeMs = debugCompile.enabled ? performance.now() : 0;
|
|
79
141
|
debugCompile("compile %s (mode=%s, registry=%d entries)", fileName, isPartial ? "partial" : "full", registry?.size ?? 0);
|
|
80
|
-
const
|
|
81
|
-
const
|
|
142
|
+
const oxcProgram = opts.oxcProgram ?? parseOxc(fileName, sourceCode).program;
|
|
143
|
+
const styleRanges = resolvedInlineStyles && inlineStyleRanges(oxcProgram);
|
|
82
144
|
const oxcClassMap = /* @__PURE__ */ new Map();
|
|
83
145
|
for (const stmt of oxcProgram.body) {
|
|
84
146
|
const decl = stmt.type === "ExportNamedDeclaration" || stmt.type === "ExportDefaultDeclaration" ? stmt.declaration : stmt;
|
|
@@ -93,19 +155,27 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
93
155
|
const typeOnlyImports = detectTypeOnlyImportNames(sourceCode, oxcProgram);
|
|
94
156
|
const importSpecifierByName = /* @__PURE__ */ new Map();
|
|
95
157
|
const importedNames = /* @__PURE__ */ new Set();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
158
|
+
const typeOnlyImportedNames = /* @__PURE__ */ new Set();
|
|
159
|
+
for (const stmt of oxcProgram.body) {
|
|
160
|
+
if (stmt.type !== "ImportDeclaration") continue;
|
|
161
|
+
const moduleSpecifier = stmt.source.value;
|
|
162
|
+
const isDeclarationTypeOnly = stmt.importKind === "type";
|
|
163
|
+
for (const element of stmt.specifiers) {
|
|
164
|
+
if (element.type !== "ImportSpecifier") continue;
|
|
165
|
+
const localName = element.local.name;
|
|
103
166
|
importSpecifierByName.set(localName, moduleSpecifier);
|
|
104
|
-
if (isDeclarationTypeOnly || element.
|
|
167
|
+
if (isDeclarationTypeOnly || element.importKind === "type") {
|
|
168
|
+
typeOnlyImports.add(localName);
|
|
169
|
+
typeOnlyImportedNames.add(localName);
|
|
170
|
+
} else importedNames.add(localName);
|
|
105
171
|
}
|
|
106
172
|
}
|
|
107
|
-
const sourceFile = injectAngularImport(origSourceFile);
|
|
108
173
|
const localSelectors = /* @__PURE__ */ new Map();
|
|
174
|
+
/**
|
|
175
|
+
* Per component class: the dependencies only its @defer blocks use, which
|
|
176
|
+
* its class metadata must load lazily (`ɵsetClassMetadataAsync`).
|
|
177
|
+
*/
|
|
178
|
+
const deferredMetadataDeps = /* @__PURE__ */ new Map();
|
|
109
179
|
if (!registry) for (const [clsName, oxcNode] of oxcClassMap) {
|
|
110
180
|
const decs = oxcNode.decorators || [];
|
|
111
181
|
if (decs.length > 0) {
|
|
@@ -114,20 +184,17 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
114
184
|
}
|
|
115
185
|
}
|
|
116
186
|
const bindingParser = isPartial ? void 0 : makeBindingParser();
|
|
117
|
-
setEmitterSourceFile(origSourceFile);
|
|
118
187
|
setEmitterSourceCode(sourceCode);
|
|
119
188
|
const classResults = [];
|
|
189
|
+
const topLevelClasses = new Set(oxcProgram.body.map((stmt) => toTopLevelStatement(stmt).decl));
|
|
120
190
|
const syntheticImports = /* @__PURE__ */ new Map();
|
|
121
|
-
|
|
122
|
-
|
|
191
|
+
const dependencyLocalName = (name) => typeOnlyImportedNames.has(name) ? `ɵngDep_${name}` : name;
|
|
192
|
+
for (const node of findAllClasses(oxcProgram)) {
|
|
193
|
+
const decorators = node.decorators;
|
|
123
194
|
if (!decorators || decorators.length === 0) continue;
|
|
124
|
-
const className = node.name
|
|
195
|
+
const className = node.id?.name;
|
|
125
196
|
if (!className) continue;
|
|
126
|
-
const angularDecorators = decorators.filter((dec) =>
|
|
127
|
-
if (!ts.isCallExpression(dec.expression)) return false;
|
|
128
|
-
const name = dec.expression.expression.getText(origSourceFile);
|
|
129
|
-
return ANGULAR_DECORATORS.has(name);
|
|
130
|
-
});
|
|
197
|
+
const angularDecorators = decorators.filter((dec) => ANGULAR_DECORATORS.has(decoratorCallName(dec, sourceCode) ?? ""));
|
|
131
198
|
if (angularDecorators.length === 0) continue;
|
|
132
199
|
const ivyCode = [];
|
|
133
200
|
let targetType = FactoryTarget.Injectable;
|
|
@@ -136,31 +203,13 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
136
203
|
value: new o.WrappedNodeExpr(className),
|
|
137
204
|
type: new o.WrappedNodeExpr(className)
|
|
138
205
|
};
|
|
139
|
-
const
|
|
140
|
-
const usesInheritance = !!extendsClause && extendsClause.types.length > 0;
|
|
141
|
-
const oxcNode = oxcClassMap.get(className);
|
|
206
|
+
const usesInheritance = !!node.superClass;
|
|
142
207
|
let classCompileError = null;
|
|
143
208
|
angularDecorators.forEach((dec) => {
|
|
144
|
-
const decoratorName = dec
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
149
|
-
const meta = extractMetadata(oxcDec, sourceCode, stringConsts);
|
|
150
|
-
const sigs = oxcNode ? detectSignals(oxcNode, sourceCode) : {
|
|
151
|
-
inputs: {},
|
|
152
|
-
outputs: {},
|
|
153
|
-
viewQueries: [],
|
|
154
|
-
contentQueries: []
|
|
155
|
-
};
|
|
156
|
-
const fields = oxcNode ? detectFieldDecorators(oxcNode, sourceCode) : {
|
|
157
|
-
inputs: {},
|
|
158
|
-
outputs: {},
|
|
159
|
-
viewQueries: [],
|
|
160
|
-
contentQueries: [],
|
|
161
|
-
hostProperties: {},
|
|
162
|
-
hostListeners: {}
|
|
163
|
-
};
|
|
209
|
+
const decoratorName = decoratorCallName(dec, sourceCode);
|
|
210
|
+
const meta = extractMetadata(dec, sourceCode, stringConsts);
|
|
211
|
+
const sigs = detectSignals(node, sourceCode);
|
|
212
|
+
const fields = detectFieldDecorators(node, sourceCode);
|
|
164
213
|
const hostBindings = parseHostBindings(meta.hostRaw || {});
|
|
165
214
|
const hostMetadata = {
|
|
166
215
|
attributes: hostBindings.attributes,
|
|
@@ -207,7 +256,7 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
207
256
|
for (const memberName of expanded) {
|
|
208
257
|
const memberEntry = registry?.get(memberName);
|
|
209
258
|
if (!memberEntry || memberEntry.kind === "tuple") continue;
|
|
210
|
-
const memberRef = new o.WrappedNodeExpr(memberName);
|
|
259
|
+
const memberRef = new o.WrappedNodeExpr(dependencyLocalName(memberName));
|
|
211
260
|
if (!importedNames.has(memberName)) {
|
|
212
261
|
const memberSpecifier = resolveSyntheticImportSpecifier(fileName, memberEntry, tupleSpecifier);
|
|
213
262
|
if (memberSpecifier) syntheticImports.set(memberName, memberSpecifier);
|
|
@@ -248,7 +297,7 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
248
297
|
const exportedEntry = registry?.get(exportedName);
|
|
249
298
|
if (exportedEntry) {
|
|
250
299
|
const kind = exportedEntry.kind === "pipe" ? 1 : 0;
|
|
251
|
-
const exportedRef = new o.WrappedNodeExpr(exportedName);
|
|
300
|
+
const exportedRef = new o.WrappedNodeExpr(dependencyLocalName(exportedName));
|
|
252
301
|
const exportedSpecifier = resolveSyntheticImportSpecifier(fileName, exportedEntry, moduleSpecifier);
|
|
253
302
|
if (exportedSpecifier) syntheticImports.set(exportedName, exportedSpecifier);
|
|
254
303
|
const decl = {
|
|
@@ -327,7 +376,7 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
327
376
|
}
|
|
328
377
|
const kind = entry.kind === "pipe" ? 1 : 0;
|
|
329
378
|
const decl = {
|
|
330
|
-
type: new o.WrappedNodeExpr(name),
|
|
379
|
+
type: new o.WrappedNodeExpr(dependencyLocalName(name)),
|
|
331
380
|
selector: entry.selector || `_unresolved-${name}`,
|
|
332
381
|
kind,
|
|
333
382
|
...kind === 1 ? { name: entry.pipeName } : {}
|
|
@@ -355,12 +404,10 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
355
404
|
} catch {
|
|
356
405
|
console.warn(`[fast-compile] Could not read style file "${url}" for ${className}`);
|
|
357
406
|
}
|
|
358
|
-
|
|
359
|
-
for (const [idx, css] of resolvedInlineStyles) if (idx < meta.styles.length) meta.styles[idx] = css;
|
|
360
|
-
}
|
|
407
|
+
for (const { index, css } of resolveInlineStyles(styleRanges?.get(dec), resolvedInlineStyles)) meta.styles[index] = css;
|
|
361
408
|
resolvedResources.set(dec, {
|
|
362
409
|
template: templateContent || void 0,
|
|
363
|
-
styles: meta.styles?.length > 0 ? [...meta.styles] : void 0
|
|
410
|
+
styles: meta.styleUrls.length > 0 && meta.styles?.length > 0 ? [...meta.styles] : void 0
|
|
364
411
|
});
|
|
365
412
|
const parsedTemplate = parseTemplate(templateContent, fileName, {
|
|
366
413
|
preserveWhitespaces: meta.preserveWhitespaces,
|
|
@@ -387,6 +434,23 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
387
434
|
classCompileError = /* @__PURE__ */ new Error(`[fast-compile] Template parse error in ${fileName} (${className}): ${firstError.msg}`);
|
|
388
435
|
return;
|
|
389
436
|
}
|
|
437
|
+
const deferDependencies = buildDeferDependencyMap(parsedTemplate, oxcProgram, registry, localSelectors);
|
|
438
|
+
if (!isPartial && deferDependencies.deferredImports.size > 0) {
|
|
439
|
+
const importMap = buildImportMap(oxcProgram);
|
|
440
|
+
const metadataDeps = [];
|
|
441
|
+
for (let i = declarations.length - 1; i >= 0; i--) {
|
|
442
|
+
const name = declarationName(declarations[i]);
|
|
443
|
+
const info = name !== null ? importMap.get(name) : void 0;
|
|
444
|
+
if (name === null || info === void 0 || !deferDependencies.deferredImports.has(name)) continue;
|
|
445
|
+
declarations.splice(i, 1);
|
|
446
|
+
metadataDeps.unshift({
|
|
447
|
+
symbolName: name,
|
|
448
|
+
importPath: info.path,
|
|
449
|
+
isDefaultImport: info.isDefault
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
if (metadataDeps.length > 0) deferredMetadataDeps.set(className, metadataDeps);
|
|
453
|
+
}
|
|
390
454
|
const componentMeta = {
|
|
391
455
|
...meta,
|
|
392
456
|
name: className,
|
|
@@ -424,7 +488,7 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
424
488
|
usesInheritance,
|
|
425
489
|
defer: {
|
|
426
490
|
mode: 0,
|
|
427
|
-
blocks:
|
|
491
|
+
blocks: deferDependencies.blocks
|
|
428
492
|
},
|
|
429
493
|
declarationListEmitMode: 1,
|
|
430
494
|
i18nUseExternalIds: opts.i18nUseExternalIds ?? false,
|
|
@@ -620,7 +684,7 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
620
684
|
}
|
|
621
685
|
});
|
|
622
686
|
if (classCompileError) throw classCompileError;
|
|
623
|
-
const deps =
|
|
687
|
+
const deps = extractConstructorDeps(node, sourceCode, typeOnlyImports);
|
|
624
688
|
if (deps === null) {
|
|
625
689
|
const baseVar = `ɵ${className}_BaseFactory`;
|
|
626
690
|
ivyCode.unshift(`static ɵfac = /*@__PURE__*/ (() => { let ${baseVar}; return function ${className}_Factory(__ngFactoryType__) { return (${baseVar} || (${baseVar} = i0.ɵɵgetInheritedFactory(${className})))(__ngFactoryType__ || ${className}); }; })()`);
|
|
@@ -641,38 +705,47 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
641
705
|
ivyCode.unshift(`static ɵfac = /*@__PURE__*/ ${emitAngularExpr(fac.expression)}`);
|
|
642
706
|
}
|
|
643
707
|
}
|
|
644
|
-
const ctorParameters =
|
|
645
|
-
const propDecorators =
|
|
708
|
+
const ctorParameters = buildCtorParameters(node, sourceCode, typeOnlyImports);
|
|
709
|
+
const propDecorators = buildPropDecorators(node, sourceCode, "i0.");
|
|
710
|
+
const scopedMetadata = [];
|
|
646
711
|
angularDecorators.forEach((dec) => {
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
const
|
|
712
|
+
const decName = decoratorCallName(dec, sourceCode);
|
|
713
|
+
const decArgsNode = dec.expression.arguments[0];
|
|
714
|
+
const textOf = (n) => sourceCode.slice(n.start, n.end);
|
|
650
715
|
const resources = resolvedResources.get(dec);
|
|
651
716
|
let metadataArgsExpr = null;
|
|
652
717
|
if (decArgsNode) {
|
|
653
|
-
if (resources &&
|
|
718
|
+
if (resources && decArgsNode.type === "ObjectExpression") {
|
|
654
719
|
const rewrittenProps = [];
|
|
655
720
|
let needsTransform = false;
|
|
721
|
+
const inlineStyles = resolveInlineStyles(styleRanges?.get(dec), resolvedInlineStyles);
|
|
722
|
+
let resourceStylesWritten = false;
|
|
656
723
|
for (const prop of decArgsNode.properties) {
|
|
657
|
-
if (
|
|
658
|
-
rewrittenProps.push(prop
|
|
724
|
+
if (prop.type !== "Property" || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
725
|
+
rewrittenProps.push(textOf(prop));
|
|
659
726
|
continue;
|
|
660
727
|
}
|
|
661
|
-
const propName = prop
|
|
728
|
+
const propName = getPropertyKey(prop);
|
|
662
729
|
if (propName === "templateUrl" && resources.template) {
|
|
663
730
|
rewrittenProps.push(`template: ${JSON.stringify(resources.template)}`);
|
|
664
731
|
needsTransform = true;
|
|
665
|
-
} else if ((propName === "styleUrl" || propName === "styleUrls") && resources.styles
|
|
666
|
-
|
|
732
|
+
} else if ((propName === "styleUrl" || propName === "styleUrls" || propName === "styles") && resources.styles) {
|
|
733
|
+
if (!resourceStylesWritten) {
|
|
734
|
+
rewrittenProps.push(`styles: [${resources.styles.map((s) => JSON.stringify(s)).join(", ")}]`);
|
|
735
|
+
resourceStylesWritten = true;
|
|
736
|
+
}
|
|
737
|
+
needsTransform = true;
|
|
738
|
+
} else if (propName === "styles" && inlineStyles.length > 0) {
|
|
739
|
+
rewrittenProps.push(`styles: ${withResolvedInlineStyles(prop.value, inlineStyles, sourceCode)}`);
|
|
667
740
|
needsTransform = true;
|
|
668
|
-
} else rewrittenProps.push(prop
|
|
741
|
+
} else rewrittenProps.push(textOf(prop));
|
|
669
742
|
}
|
|
670
|
-
metadataArgsExpr = needsTransform ? `{${rewrittenProps.join(", ")}}` : decArgsNode
|
|
671
|
-
} else metadataArgsExpr = decArgsNode
|
|
743
|
+
metadataArgsExpr = needsTransform ? `{${rewrittenProps.join(", ")}}` : textOf(decArgsNode);
|
|
744
|
+
} else metadataArgsExpr = textOf(decArgsNode);
|
|
672
745
|
}
|
|
673
746
|
try {
|
|
674
747
|
const classMetaInput = {
|
|
675
|
-
type: new o.WrappedNodeExpr(
|
|
748
|
+
type: new o.WrappedNodeExpr(className),
|
|
676
749
|
decorators: new o.LiteralArrayExpr([new o.LiteralMapExpr([{
|
|
677
750
|
key: "type",
|
|
678
751
|
value: new o.WrappedNodeExpr(decName),
|
|
@@ -685,74 +758,69 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
685
758
|
ctorParameters: ctorParameters ? new o.WrappedNodeExpr(`() => [${ctorParameters}]`) : null,
|
|
686
759
|
propDecorators: propDecorators ? new o.WrappedNodeExpr(propDecorators) : null
|
|
687
760
|
};
|
|
688
|
-
const
|
|
689
|
-
|
|
761
|
+
const deferredDeps = decName === "Component" ? deferredMetadataDeps.get(className) : void 0;
|
|
762
|
+
const classMetadataExpr = isPartial ? compileDeclareClassMetadata(classMetaInput) : deferredDeps ? compileComponentClassMetadata(classMetaInput, deferredDeps) : compileClassMetadata(classMetaInput);
|
|
763
|
+
const metadataStmt = new o.ExpressionStatement(classMetadataExpr);
|
|
764
|
+
if (topLevelClasses.has(node)) constantPool.statements.push(metadataStmt);
|
|
765
|
+
else scopedMetadata.push(metadataStmt);
|
|
690
766
|
} catch (e) {
|
|
691
767
|
if (debugCompile.enabled) debugCompile("compileClassMetadata failed for %s in %s: %s", className, fileName, e?.message);
|
|
692
768
|
}
|
|
693
769
|
});
|
|
694
770
|
const memberDecorators = [];
|
|
695
|
-
for (const member of node.
|
|
696
|
-
const mDecorators = ts.getDecorators(member);
|
|
697
|
-
if (!mDecorators) continue;
|
|
698
|
-
for (const dec of mDecorators) {
|
|
699
|
-
if (!ts.isCallExpression(dec.expression)) continue;
|
|
700
|
-
const decName = dec.expression.expression.getText(origSourceFile);
|
|
701
|
-
if (FIELD_DECORATORS.has(decName)) memberDecorators.push(dec);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
771
|
+
for (const member of node.body.body) for (const dec of member.decorators ?? []) if (FIELD_DECORATORS.has(decoratorCallName(dec, sourceCode) ?? "")) memberDecorators.push(dec);
|
|
704
772
|
classResults.push({
|
|
705
773
|
ivyCode,
|
|
706
774
|
decorators: [...angularDecorators, ...memberDecorators],
|
|
707
|
-
classEnd: node.
|
|
775
|
+
classEnd: node.end,
|
|
776
|
+
scopedMetadata
|
|
708
777
|
});
|
|
709
778
|
}
|
|
710
779
|
const ms = new MagicString(sourceCode, { filename: fileName });
|
|
711
780
|
if (!sourceCode.includes("import * as i0 from")) ms.prepend("import * as i0 from \"@angular/core\";\n");
|
|
712
|
-
for (const [name, specifier] of syntheticImports)
|
|
713
|
-
|
|
714
|
-
importedNames.
|
|
781
|
+
for (const [name, specifier] of syntheticImports) {
|
|
782
|
+
const localName = dependencyLocalName(name);
|
|
783
|
+
if (!importedNames.has(localName)) {
|
|
784
|
+
const binding = localName === name ? name : `${name} as ${localName}`;
|
|
785
|
+
ms.prepend(`import { ${binding} } from "${specifier}";\n`);
|
|
786
|
+
importedNames.add(localName);
|
|
787
|
+
}
|
|
715
788
|
}
|
|
716
789
|
if (classResults.length > 0) {
|
|
790
|
+
const statements = oxcProgram.body.map(toTopLevelStatement);
|
|
717
791
|
let firstClassPos = Infinity;
|
|
718
792
|
const nonHoistableNames = /* @__PURE__ */ new Set();
|
|
719
|
-
for (const
|
|
720
|
-
firstClassPos =
|
|
721
|
-
if (
|
|
793
|
+
for (const { decl, start } of statements) if (decl.type === "ClassDeclaration") {
|
|
794
|
+
firstClassPos = start;
|
|
795
|
+
if (decl.id) nonHoistableNames.add(decl.id.name);
|
|
722
796
|
break;
|
|
723
797
|
}
|
|
724
|
-
for (const
|
|
725
|
-
if (
|
|
726
|
-
if (
|
|
727
|
-
|
|
728
|
-
if (
|
|
729
|
-
const names = [];
|
|
730
|
-
collectBindingNames(decl.name, names);
|
|
731
|
-
for (const n of names) nonHoistableNames.add(n);
|
|
732
|
-
}
|
|
733
|
-
if (ts.isFunctionDeclaration(stmt) && hasExportModifier(stmt) && stmt.name) nonHoistableNames.add(stmt.name.text);
|
|
798
|
+
for (const { decl, exported, start } of statements) {
|
|
799
|
+
if (start <= firstClassPos) continue;
|
|
800
|
+
if (decl.type === "ClassDeclaration" || decl.type === "TSEnumDeclaration") {
|
|
801
|
+
if (decl.id) nonHoistableNames.add(decl.id.name);
|
|
802
|
+
} else if (exported && (decl.type === "VariableDeclaration" || decl.type === "FunctionDeclaration")) for (const n of getDefinedNames(decl)) nonHoistableNames.add(n);
|
|
734
803
|
}
|
|
735
|
-
for (const
|
|
736
|
-
|
|
737
|
-
if (
|
|
738
|
-
|
|
739
|
-
const referencedIds = collectIdentifiers(stmt);
|
|
804
|
+
for (const { decl, exported, start, end } of statements) {
|
|
805
|
+
if (start <= firstClassPos) continue;
|
|
806
|
+
if (!(!exported && (decl.type === "VariableDeclaration" || decl.type === "FunctionDeclaration"))) continue;
|
|
807
|
+
const referencedIds = collectIdentifiers(decl);
|
|
740
808
|
let referencesNonHoistable = false;
|
|
741
809
|
for (const id of referencedIds) if (nonHoistableNames.has(id)) {
|
|
742
810
|
referencesNonHoistable = true;
|
|
743
811
|
break;
|
|
744
812
|
}
|
|
745
|
-
if (referencesNonHoistable) for (const name of getDefinedNames(
|
|
813
|
+
if (referencesNonHoistable) for (const name of getDefinedNames(decl)) nonHoistableNames.add(name);
|
|
746
814
|
else {
|
|
747
|
-
ms.appendLeft(
|
|
748
|
-
ms.move(
|
|
815
|
+
ms.appendLeft(end, "\n");
|
|
816
|
+
ms.move(start, end, firstClassPos);
|
|
749
817
|
}
|
|
750
818
|
}
|
|
751
819
|
}
|
|
752
820
|
for (const cr of classResults) {
|
|
753
821
|
for (const dec of cr.decorators) {
|
|
754
|
-
const start = dec.
|
|
755
|
-
let trimEnd = dec.
|
|
822
|
+
const start = dec.start;
|
|
823
|
+
let trimEnd = dec.end;
|
|
756
824
|
while (trimEnd < sourceCode.length && (sourceCode[trimEnd] === " " || sourceCode[trimEnd] === "\n" || sourceCode[trimEnd] === "\r")) trimEnd++;
|
|
757
825
|
ms.remove(start, trimEnd);
|
|
758
826
|
}
|
|
@@ -760,6 +828,7 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
760
828
|
const memberCode = cr.ivyCode.map((c) => " " + c + ";").join("\n");
|
|
761
829
|
ms.appendLeft(cr.classEnd - 1, "\n" + memberCode + "\n");
|
|
762
830
|
}
|
|
831
|
+
for (const stmt of cr.scopedMetadata) ms.appendLeft(cr.classEnd, `\n/*@__PURE__*/ ${emitAngularStmt(stmt)}`);
|
|
763
832
|
}
|
|
764
833
|
const helpers = [];
|
|
765
834
|
const sideEffects = [];
|
|
@@ -768,25 +837,26 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
768
837
|
if (s instanceof o.ExpressionStatement && s.expr instanceof o.InvokeFunctionExpr) sideEffects.push(`/*@__PURE__*/ ${code}`);
|
|
769
838
|
else helpers.push(code);
|
|
770
839
|
}
|
|
840
|
+
if (sideEffects.length > 0) ms.append("\n\n" + sideEffects.join("\n"));
|
|
841
|
+
if (!useDefineForClassFields) lowerClassFields(ms, sourceCode, oxcProgram);
|
|
842
|
+
const helperCode = helpers.join("\n");
|
|
843
|
+
const willElide = detectTypeOnlyImportNames(ms.toString() + "\n" + helperCode);
|
|
771
844
|
if (helpers.length > 0) {
|
|
772
|
-
const willElide = detectTypeOnlyImportNames(ms.toString());
|
|
773
845
|
let insertPos = 0;
|
|
774
|
-
for (const stmt of
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
insertPos = stmt.
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
if (insertPos === 0) ms.appendLeft(0,
|
|
785
|
-
else ms.appendRight(insertPos, "\n" +
|
|
846
|
+
for (const stmt of oxcProgram.body) {
|
|
847
|
+
const { decl } = toTopLevelStatement(stmt);
|
|
848
|
+
if (stmt.type === "ImportDeclaration") {
|
|
849
|
+
if (willElide.size > 0 && stmt.specifiers.length > 0) {
|
|
850
|
+
if (stmt.specifiers.every((spec) => spec.type === "ImportNamespaceSpecifier" || spec.importKind === "type" || willElide.has(spec.local.name))) continue;
|
|
851
|
+
}
|
|
852
|
+
insertPos = stmt.end;
|
|
853
|
+
} else if (decl.type === "VariableDeclaration" && !sourceCode.slice(stmt.start, stmt.end).includes("class")) insertPos = stmt.end;
|
|
854
|
+
else if (stmt.type !== "TSExportAssignment" && !(stmt.type === "ExportDefaultDeclaration" && decl.type !== "ClassDeclaration" && decl.type !== "FunctionDeclaration")) break;
|
|
855
|
+
}
|
|
856
|
+
if (insertPos === 0) ms.appendLeft(0, helperCode + "\n");
|
|
857
|
+
else ms.appendRight(insertPos, "\n" + helperCode + "\n");
|
|
786
858
|
}
|
|
787
|
-
|
|
788
|
-
if (!useDefineForClassFields) lowerClassFields(ms, sourceCode, oxcProgram);
|
|
789
|
-
elideTypeOnlyImportsMagicString(ms, oxcProgram);
|
|
859
|
+
elideTypeOnlyImportsMagicString(ms, oxcProgram, willElide);
|
|
790
860
|
const map = ms.generateMap({
|
|
791
861
|
source: fileName,
|
|
792
862
|
file: fileName + ".js",
|
|
@@ -800,10 +870,13 @@ function compile(sourceCode, fileName, optionsOrRegistry) {
|
|
|
800
870
|
resourceDependencies
|
|
801
871
|
};
|
|
802
872
|
}
|
|
803
|
-
|
|
804
|
-
|
|
873
|
+
/** The local class name an `imports` entry declares, when it is a plain identifier. */
|
|
874
|
+
function declarationName(declaration) {
|
|
875
|
+
const node = declaration.type.node;
|
|
876
|
+
if (typeof node === "string") return node;
|
|
877
|
+
if (node?.type === "Identifier" && typeof node.name === "string") return node.name;
|
|
878
|
+
return declaration.className ?? null;
|
|
805
879
|
}
|
|
806
|
-
//#endregion
|
|
807
880
|
export { compile };
|
|
808
881
|
|
|
809
882
|
//# sourceMappingURL=compile.js.map
|