Primeiro commit do projeto Angular
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/logging/src/logger.js
|
||||
var LogLevel;
|
||||
(function(LogLevel2) {
|
||||
LogLevel2[LogLevel2["debug"] = 0] = "debug";
|
||||
LogLevel2[LogLevel2["info"] = 1] = "info";
|
||||
LogLevel2[LogLevel2["warn"] = 2] = "warn";
|
||||
LogLevel2[LogLevel2["error"] = 3] = "error";
|
||||
})(LogLevel || (LogLevel = {}));
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/logging/src/console_logger.js
|
||||
var RESET = "\x1B[0m";
|
||||
var RED = "\x1B[31m";
|
||||
var YELLOW = "\x1B[33m";
|
||||
var BLUE = "\x1B[36m";
|
||||
var DEBUG = `${BLUE}Debug:${RESET}`;
|
||||
var WARN = `${YELLOW}Warning:${RESET}`;
|
||||
var ERROR = `${RED}Error:${RESET}`;
|
||||
var ConsoleLogger = class {
|
||||
level;
|
||||
constructor(level) {
|
||||
this.level = level;
|
||||
}
|
||||
debug(...args) {
|
||||
if (this.level <= LogLevel.debug)
|
||||
console.debug(DEBUG, ...args);
|
||||
}
|
||||
info(...args) {
|
||||
if (this.level <= LogLevel.info)
|
||||
console.info(...args);
|
||||
}
|
||||
warn(...args) {
|
||||
if (this.level <= LogLevel.warn)
|
||||
console.warn(WARN, ...args);
|
||||
}
|
||||
error(...args) {
|
||||
if (this.level <= LogLevel.error)
|
||||
console.error(ERROR, ...args);
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
LogLevel,
|
||||
ConsoleLogger
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+373
@@ -0,0 +1,373 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/src/invalid_file_system.js
|
||||
var InvalidFileSystem = class {
|
||||
exists(path) {
|
||||
throw makeError();
|
||||
}
|
||||
readFile(path) {
|
||||
throw makeError();
|
||||
}
|
||||
readFileBuffer(path) {
|
||||
throw makeError();
|
||||
}
|
||||
writeFile(path, data, exclusive) {
|
||||
throw makeError();
|
||||
}
|
||||
removeFile(path) {
|
||||
throw makeError();
|
||||
}
|
||||
symlink(target, path) {
|
||||
throw makeError();
|
||||
}
|
||||
readdir(path) {
|
||||
throw makeError();
|
||||
}
|
||||
lstat(path) {
|
||||
throw makeError();
|
||||
}
|
||||
stat(path) {
|
||||
throw makeError();
|
||||
}
|
||||
pwd() {
|
||||
throw makeError();
|
||||
}
|
||||
chdir(path) {
|
||||
throw makeError();
|
||||
}
|
||||
extname(path) {
|
||||
throw makeError();
|
||||
}
|
||||
copyFile(from, to) {
|
||||
throw makeError();
|
||||
}
|
||||
moveFile(from, to) {
|
||||
throw makeError();
|
||||
}
|
||||
ensureDir(path) {
|
||||
throw makeError();
|
||||
}
|
||||
removeDeep(path) {
|
||||
throw makeError();
|
||||
}
|
||||
isCaseSensitive() {
|
||||
throw makeError();
|
||||
}
|
||||
resolve(...paths) {
|
||||
throw makeError();
|
||||
}
|
||||
dirname(file) {
|
||||
throw makeError();
|
||||
}
|
||||
join(basePath, ...paths) {
|
||||
throw makeError();
|
||||
}
|
||||
isRoot(path) {
|
||||
throw makeError();
|
||||
}
|
||||
isRooted(path) {
|
||||
throw makeError();
|
||||
}
|
||||
relative(from, to) {
|
||||
throw makeError();
|
||||
}
|
||||
basename(filePath, extension) {
|
||||
throw makeError();
|
||||
}
|
||||
realpath(filePath) {
|
||||
throw makeError();
|
||||
}
|
||||
getDefaultLibLocation() {
|
||||
throw makeError();
|
||||
}
|
||||
normalize(path) {
|
||||
throw makeError();
|
||||
}
|
||||
};
|
||||
function makeError() {
|
||||
return new Error("FileSystem has not been configured. Please call `setFileSystem()` before calling this method.");
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/src/util.js
|
||||
var TS_DTS_TSX_JS_EXTENSION = /(?:\.d)?\.ts$|\.tsx$|\.js$/;
|
||||
function normalizeSeparators(path) {
|
||||
return path.replace(/\\/g, "/");
|
||||
}
|
||||
function stripExtension(path) {
|
||||
return path.replace(TS_DTS_TSX_JS_EXTENSION, "");
|
||||
}
|
||||
function getSourceFileOrError(program, fileName) {
|
||||
const sf = program.getSourceFile(fileName);
|
||||
if (sf === void 0) {
|
||||
throw new Error(`Program does not contain "${fileName}" - available files are ${program.getSourceFiles().map((sf2) => sf2.fileName).join(", ")}`);
|
||||
}
|
||||
return sf;
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/src/helpers.js
|
||||
var fs = new InvalidFileSystem();
|
||||
function getFileSystem() {
|
||||
return fs;
|
||||
}
|
||||
function setFileSystem(fileSystem) {
|
||||
fs = fileSystem;
|
||||
}
|
||||
function absoluteFrom(path) {
|
||||
if (!fs.isRooted(path)) {
|
||||
throw new Error(`Internal Error: absoluteFrom(${path}): path is not absolute`);
|
||||
}
|
||||
return fs.resolve(path);
|
||||
}
|
||||
var ABSOLUTE_PATH = Symbol("AbsolutePath");
|
||||
function absoluteFromSourceFile(sf) {
|
||||
const sfWithPatch = sf;
|
||||
if (sfWithPatch[ABSOLUTE_PATH] === void 0) {
|
||||
sfWithPatch[ABSOLUTE_PATH] = fs.resolve(sfWithPatch.fileName);
|
||||
}
|
||||
return sfWithPatch[ABSOLUTE_PATH];
|
||||
}
|
||||
function relativeFrom(path) {
|
||||
const normalized = normalizeSeparators(path);
|
||||
if (fs.isRooted(normalized)) {
|
||||
throw new Error(`Internal Error: relativeFrom(${path}): path is not relative`);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
function dirname(file) {
|
||||
return fs.dirname(file);
|
||||
}
|
||||
function join(basePath, ...paths) {
|
||||
return fs.join(basePath, ...paths);
|
||||
}
|
||||
function resolve(basePath, ...paths) {
|
||||
return fs.resolve(basePath, ...paths);
|
||||
}
|
||||
function isRoot(path) {
|
||||
return fs.isRoot(path);
|
||||
}
|
||||
function isRooted(path) {
|
||||
return fs.isRooted(path);
|
||||
}
|
||||
function relative(from, to) {
|
||||
return fs.relative(from, to);
|
||||
}
|
||||
function basename(filePath, extension) {
|
||||
return fs.basename(filePath, extension);
|
||||
}
|
||||
function isLocalRelativePath(relativePath) {
|
||||
return !isRooted(relativePath) && !relativePath.startsWith("..");
|
||||
}
|
||||
function toRelativeImport(relativePath) {
|
||||
return isLocalRelativePath(relativePath) ? `./${relativePath}` : relativePath;
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/src/compiler_host.js
|
||||
import * as os from "os";
|
||||
import ts from "typescript";
|
||||
var NgtscCompilerHost = class {
|
||||
fs;
|
||||
options;
|
||||
constructor(fs2, options = {}) {
|
||||
this.fs = fs2;
|
||||
this.options = options;
|
||||
}
|
||||
getSourceFile(fileName, languageVersion) {
|
||||
const text = this.readFile(fileName);
|
||||
return text !== void 0 ? ts.createSourceFile(fileName, text, languageVersion, true) : void 0;
|
||||
}
|
||||
getDefaultLibFileName(options) {
|
||||
return this.fs.join(this.getDefaultLibLocation(), ts.getDefaultLibFileName(options));
|
||||
}
|
||||
getDefaultLibLocation() {
|
||||
return this.fs.getDefaultLibLocation();
|
||||
}
|
||||
writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles) {
|
||||
const path = absoluteFrom(fileName);
|
||||
this.fs.ensureDir(this.fs.dirname(path));
|
||||
this.fs.writeFile(path, data);
|
||||
}
|
||||
getCurrentDirectory() {
|
||||
return this.fs.pwd();
|
||||
}
|
||||
getCanonicalFileName(fileName) {
|
||||
return this.useCaseSensitiveFileNames() ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
useCaseSensitiveFileNames() {
|
||||
return this.fs.isCaseSensitive();
|
||||
}
|
||||
getNewLine() {
|
||||
switch (this.options.newLine) {
|
||||
case ts.NewLineKind.CarriageReturnLineFeed:
|
||||
return "\r\n";
|
||||
case ts.NewLineKind.LineFeed:
|
||||
return "\n";
|
||||
default:
|
||||
return os.EOL;
|
||||
}
|
||||
}
|
||||
fileExists(fileName) {
|
||||
const absPath = this.fs.resolve(fileName);
|
||||
return this.fs.exists(absPath) && this.fs.stat(absPath).isFile();
|
||||
}
|
||||
readFile(fileName) {
|
||||
const absPath = this.fs.resolve(fileName);
|
||||
if (!this.fileExists(absPath)) {
|
||||
return void 0;
|
||||
}
|
||||
return this.fs.readFile(absPath);
|
||||
}
|
||||
realpath(path) {
|
||||
return this.fs.realpath(this.fs.resolve(path));
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/src/logical.js
|
||||
var LogicalProjectPath = {
|
||||
/**
|
||||
* Get the relative path between two `LogicalProjectPath`s.
|
||||
*
|
||||
* This will return a `PathSegment` which would be a valid module specifier to use in `from` when
|
||||
* importing from `to`.
|
||||
*/
|
||||
relativePathBetween: function(from, to) {
|
||||
const relativePath = relative(dirname(resolve(from)), resolve(to));
|
||||
return toRelativeImport(relativePath);
|
||||
}
|
||||
};
|
||||
var LogicalFileSystem = class {
|
||||
compilerHost;
|
||||
/**
|
||||
* The root directories of the project, sorted with the longest path first.
|
||||
*/
|
||||
rootDirs;
|
||||
/**
|
||||
* The same root directories as `rootDirs` but with each one converted to its
|
||||
* canonical form for matching in case-insensitive file-systems.
|
||||
*/
|
||||
canonicalRootDirs;
|
||||
/**
|
||||
* A cache of file paths to project paths, because computation of these paths is slightly
|
||||
* expensive.
|
||||
*/
|
||||
cache = /* @__PURE__ */ new Map();
|
||||
constructor(rootDirs, compilerHost) {
|
||||
this.compilerHost = compilerHost;
|
||||
this.rootDirs = rootDirs.concat([]).sort((a, b) => b.length - a.length);
|
||||
this.canonicalRootDirs = this.rootDirs.map((dir) => this.compilerHost.getCanonicalFileName(dir));
|
||||
}
|
||||
/**
|
||||
* Get the logical path in the project of a `ts.SourceFile`.
|
||||
*
|
||||
* This method is provided as a convenient alternative to calling
|
||||
* `logicalPathOfFile(absoluteFromSourceFile(sf))`.
|
||||
*/
|
||||
logicalPathOfSf(sf) {
|
||||
return this.logicalPathOfFile(absoluteFromSourceFile(sf));
|
||||
}
|
||||
/**
|
||||
* Get the logical path in the project of a source file.
|
||||
*
|
||||
* @returns A `LogicalProjectPath` to the source file, or `null` if the source file is not in any
|
||||
* of the TS project's root directories.
|
||||
*/
|
||||
logicalPathOfFile(physicalFile) {
|
||||
if (!this.cache.has(physicalFile)) {
|
||||
const canonicalFilePath = this.compilerHost.getCanonicalFileName(physicalFile);
|
||||
let logicalFile = null;
|
||||
for (let i = 0; i < this.rootDirs.length; i++) {
|
||||
const rootDir = this.rootDirs[i];
|
||||
const canonicalRootDir = this.canonicalRootDirs[i];
|
||||
if (isWithinBasePath(canonicalRootDir, canonicalFilePath)) {
|
||||
logicalFile = this.createLogicalProjectPath(physicalFile, rootDir);
|
||||
if (logicalFile.indexOf("/node_modules/") !== -1) {
|
||||
logicalFile = null;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.cache.set(physicalFile, logicalFile);
|
||||
}
|
||||
return this.cache.get(physicalFile);
|
||||
}
|
||||
createLogicalProjectPath(file, rootDir) {
|
||||
const logicalPath = stripExtension(file.slice(rootDir.length));
|
||||
return logicalPath.startsWith("/") ? logicalPath : "/" + logicalPath;
|
||||
}
|
||||
};
|
||||
function isWithinBasePath(base, path) {
|
||||
return isLocalRelativePath(relative(base, path));
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/src/ts_read_directory.js
|
||||
import ts2 from "typescript";
|
||||
function createFileSystemTsReadDirectoryFn(fs2) {
|
||||
if (ts2.matchFiles === void 0) {
|
||||
throw Error("Unable to read directory in configured file system. This means that TypeScript changed its file matching internals.\n\nPlease consider downgrading your TypeScript version, and report an issue in the Angular framework repository.");
|
||||
}
|
||||
const matchFilesFn = ts2.matchFiles.bind(ts2);
|
||||
return (rootDir, extensions, excludes, includes, depth) => {
|
||||
const directoryExists = (p) => {
|
||||
const resolvedPath = fs2.resolve(p);
|
||||
return fs2.exists(resolvedPath) && fs2.stat(resolvedPath).isDirectory();
|
||||
};
|
||||
return matchFilesFn(rootDir, extensions, excludes, includes, fs2.isCaseSensitive(), fs2.pwd(), depth, (p) => {
|
||||
const resolvedPath = fs2.resolve(p);
|
||||
if (!directoryExists(resolvedPath)) {
|
||||
return { directories: [], files: [] };
|
||||
}
|
||||
const children = fs2.readdir(resolvedPath);
|
||||
const files = [];
|
||||
const directories = [];
|
||||
for (const child of children) {
|
||||
try {
|
||||
if (fs2.stat(fs2.join(resolvedPath, child))?.isDirectory()) {
|
||||
directories.push(child);
|
||||
} else {
|
||||
files.push(child);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error && error.message.includes("ENOENT")) {
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return { files, directories };
|
||||
}, (p) => fs2.resolve(p), (p) => directoryExists(p));
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
InvalidFileSystem,
|
||||
stripExtension,
|
||||
getSourceFileOrError,
|
||||
getFileSystem,
|
||||
setFileSystem,
|
||||
absoluteFrom,
|
||||
absoluteFromSourceFile,
|
||||
relativeFrom,
|
||||
dirname,
|
||||
join,
|
||||
resolve,
|
||||
isRoot,
|
||||
isRooted,
|
||||
relative,
|
||||
basename,
|
||||
isLocalRelativePath,
|
||||
toRelativeImport,
|
||||
NgtscCompilerHost,
|
||||
LogicalProjectPath,
|
||||
LogicalFileSystem,
|
||||
createFileSystemTsReadDirectoryFn
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+313
@@ -0,0 +1,313 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/translator/src/context.js
|
||||
var Context = class _Context {
|
||||
isStatement;
|
||||
constructor(isStatement) {
|
||||
this.isStatement = isStatement;
|
||||
}
|
||||
get withExpressionMode() {
|
||||
return this.isStatement ? new _Context(false) : this;
|
||||
}
|
||||
get withStatementMode() {
|
||||
return !this.isStatement ? new _Context(true) : this;
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/translator/src/translator.js
|
||||
import * as o from "@angular/compiler";
|
||||
var UNARY_OPERATORS = /* @__PURE__ */ new Map([
|
||||
[o.UnaryOperator.Minus, "-"],
|
||||
[o.UnaryOperator.Plus, "+"]
|
||||
]);
|
||||
var BINARY_OPERATORS = /* @__PURE__ */ new Map([
|
||||
[o.BinaryOperator.And, "&&"],
|
||||
[o.BinaryOperator.Bigger, ">"],
|
||||
[o.BinaryOperator.BiggerEquals, ">="],
|
||||
[o.BinaryOperator.BitwiseAnd, "&"],
|
||||
[o.BinaryOperator.BitwiseOr, "|"],
|
||||
[o.BinaryOperator.Divide, "/"],
|
||||
[o.BinaryOperator.Equals, "=="],
|
||||
[o.BinaryOperator.Identical, "==="],
|
||||
[o.BinaryOperator.Lower, "<"],
|
||||
[o.BinaryOperator.LowerEquals, "<="],
|
||||
[o.BinaryOperator.Minus, "-"],
|
||||
[o.BinaryOperator.Modulo, "%"],
|
||||
[o.BinaryOperator.Multiply, "*"],
|
||||
[o.BinaryOperator.NotEquals, "!="],
|
||||
[o.BinaryOperator.NotIdentical, "!=="],
|
||||
[o.BinaryOperator.Or, "||"],
|
||||
[o.BinaryOperator.Plus, "+"],
|
||||
[o.BinaryOperator.NullishCoalesce, "??"],
|
||||
[o.BinaryOperator.Exponentiation, "**"],
|
||||
[o.BinaryOperator.In, "in"],
|
||||
[o.BinaryOperator.InstanceOf, "instanceof"],
|
||||
[o.BinaryOperator.Assign, "="],
|
||||
[o.BinaryOperator.AdditionAssignment, "+="],
|
||||
[o.BinaryOperator.SubtractionAssignment, "-="],
|
||||
[o.BinaryOperator.MultiplicationAssignment, "*="],
|
||||
[o.BinaryOperator.DivisionAssignment, "/="],
|
||||
[o.BinaryOperator.RemainderAssignment, "%="],
|
||||
[o.BinaryOperator.ExponentiationAssignment, "**="],
|
||||
[o.BinaryOperator.AndAssignment, "&&="],
|
||||
[o.BinaryOperator.OrAssignment, "||="],
|
||||
[o.BinaryOperator.NullishCoalesceAssignment, "??="]
|
||||
]);
|
||||
var ExpressionTranslatorVisitor = class {
|
||||
factory;
|
||||
imports;
|
||||
contextFile;
|
||||
downlevelTaggedTemplates;
|
||||
downlevelVariableDeclarations;
|
||||
recordWrappedNode;
|
||||
constructor(factory, imports, contextFile, options) {
|
||||
this.factory = factory;
|
||||
this.imports = imports;
|
||||
this.contextFile = contextFile;
|
||||
this.downlevelTaggedTemplates = options.downlevelTaggedTemplates === true;
|
||||
this.downlevelVariableDeclarations = options.downlevelVariableDeclarations === true;
|
||||
this.recordWrappedNode = options.recordWrappedNode || (() => {
|
||||
});
|
||||
}
|
||||
visitDeclareVarStmt(stmt, context) {
|
||||
const varType = this.downlevelVariableDeclarations ? "var" : stmt.hasModifier(o.StmtModifier.Final) ? "const" : "let";
|
||||
return this.attachComments(this.factory.createVariableDeclaration(stmt.name, stmt.value?.visitExpression(this, context.withExpressionMode), varType), stmt.leadingComments);
|
||||
}
|
||||
visitDeclareFunctionStmt(stmt, context) {
|
||||
return this.attachComments(this.factory.createFunctionDeclaration(stmt.name, stmt.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(stmt.statements, context.withStatementMode))), stmt.leadingComments);
|
||||
}
|
||||
visitExpressionStmt(stmt, context) {
|
||||
return this.attachComments(this.factory.createExpressionStatement(stmt.expr.visitExpression(this, context.withStatementMode)), stmt.leadingComments);
|
||||
}
|
||||
visitReturnStmt(stmt, context) {
|
||||
return this.attachComments(this.factory.createReturnStatement(stmt.value.visitExpression(this, context.withExpressionMode)), stmt.leadingComments);
|
||||
}
|
||||
visitIfStmt(stmt, context) {
|
||||
return this.attachComments(this.factory.createIfStatement(stmt.condition.visitExpression(this, context), this.factory.createBlock(this.visitStatements(stmt.trueCase, context.withStatementMode)), stmt.falseCase.length > 0 ? this.factory.createBlock(this.visitStatements(stmt.falseCase, context.withStatementMode)) : null), stmt.leadingComments);
|
||||
}
|
||||
visitReadVarExpr(ast, _context) {
|
||||
const identifier = this.factory.createIdentifier(ast.name);
|
||||
this.setSourceMapRange(identifier, ast.sourceSpan);
|
||||
return identifier;
|
||||
}
|
||||
visitInvokeFunctionExpr(ast, context) {
|
||||
return this.setSourceMapRange(this.factory.createCallExpression(ast.fn.visitExpression(this, context), ast.args.map((arg) => arg.visitExpression(this, context)), ast.pure), ast.sourceSpan);
|
||||
}
|
||||
visitTaggedTemplateLiteralExpr(ast, context) {
|
||||
return this.setSourceMapRange(this.createTaggedTemplateExpression(ast.tag.visitExpression(this, context), this.getTemplateLiteralFromAst(ast.template, context)), ast.sourceSpan);
|
||||
}
|
||||
visitTemplateLiteralExpr(ast, context) {
|
||||
return this.setSourceMapRange(this.factory.createTemplateLiteral(this.getTemplateLiteralFromAst(ast, context)), ast.sourceSpan);
|
||||
}
|
||||
visitInstantiateExpr(ast, context) {
|
||||
return this.factory.createNewExpression(ast.classExpr.visitExpression(this, context), ast.args.map((arg) => arg.visitExpression(this, context)));
|
||||
}
|
||||
visitLiteralExpr(ast, _context) {
|
||||
return this.setSourceMapRange(this.factory.createLiteral(ast.value), ast.sourceSpan);
|
||||
}
|
||||
visitRegularExpressionLiteral(ast, context) {
|
||||
return this.setSourceMapRange(this.factory.createRegularExpressionLiteral(ast.body, ast.flags), ast.sourceSpan);
|
||||
}
|
||||
visitLocalizedString(ast, context) {
|
||||
const elements = [createTemplateElement(ast.serializeI18nHead())];
|
||||
const expressions = [];
|
||||
for (let i = 0; i < ast.expressions.length; i++) {
|
||||
const placeholder = this.setSourceMapRange(ast.expressions[i].visitExpression(this, context), ast.getPlaceholderSourceSpan(i));
|
||||
expressions.push(placeholder);
|
||||
elements.push(createTemplateElement(ast.serializeI18nTemplatePart(i + 1)));
|
||||
}
|
||||
const localizeTag = this.factory.createIdentifier("$localize");
|
||||
return this.setSourceMapRange(this.createTaggedTemplateExpression(localizeTag, { elements, expressions }), ast.sourceSpan);
|
||||
}
|
||||
createTaggedTemplateExpression(tag, template) {
|
||||
return this.downlevelTaggedTemplates ? this.createES5TaggedTemplateFunctionCall(tag, template) : this.factory.createTaggedTemplate(tag, template);
|
||||
}
|
||||
/**
|
||||
* Translate the tagged template literal into a call that is compatible with ES5, using the
|
||||
* imported `__makeTemplateObject` helper for ES5 formatted output.
|
||||
*/
|
||||
createES5TaggedTemplateFunctionCall(tagHandler, { elements, expressions }) {
|
||||
const __makeTemplateObjectHelper = this.imports.addImport({
|
||||
exportModuleSpecifier: "tslib",
|
||||
exportSymbolName: "__makeTemplateObject",
|
||||
requestedFile: this.contextFile
|
||||
});
|
||||
const cooked = [];
|
||||
const raw = [];
|
||||
for (const element of elements) {
|
||||
cooked.push(this.factory.setSourceMapRange(this.factory.createLiteral(element.cooked), element.range));
|
||||
raw.push(this.factory.setSourceMapRange(this.factory.createLiteral(element.raw), element.range));
|
||||
}
|
||||
const templateHelperCall = this.factory.createCallExpression(
|
||||
__makeTemplateObjectHelper,
|
||||
[this.factory.createArrayLiteral(cooked), this.factory.createArrayLiteral(raw)],
|
||||
/* pure */
|
||||
false
|
||||
);
|
||||
return this.factory.createCallExpression(
|
||||
tagHandler,
|
||||
[templateHelperCall, ...expressions],
|
||||
/* pure */
|
||||
false
|
||||
);
|
||||
}
|
||||
visitExternalExpr(ast, _context) {
|
||||
if (ast.value.name === null) {
|
||||
if (ast.value.moduleName === null) {
|
||||
throw new Error("Invalid import without name nor moduleName");
|
||||
}
|
||||
return this.imports.addImport({
|
||||
exportModuleSpecifier: ast.value.moduleName,
|
||||
exportSymbolName: null,
|
||||
requestedFile: this.contextFile
|
||||
});
|
||||
}
|
||||
if (ast.value.moduleName !== null) {
|
||||
return this.imports.addImport({
|
||||
exportModuleSpecifier: ast.value.moduleName,
|
||||
exportSymbolName: ast.value.name,
|
||||
requestedFile: this.contextFile
|
||||
});
|
||||
} else {
|
||||
return this.factory.createIdentifier(ast.value.name);
|
||||
}
|
||||
}
|
||||
visitConditionalExpr(ast, context) {
|
||||
return this.factory.createConditional(ast.condition.visitExpression(this, context), ast.trueCase.visitExpression(this, context), ast.falseCase.visitExpression(this, context));
|
||||
}
|
||||
visitDynamicImportExpr(ast, context) {
|
||||
const urlExpression = typeof ast.url === "string" ? this.factory.createLiteral(ast.url) : ast.url.visitExpression(this, context);
|
||||
if (ast.urlComment) {
|
||||
this.factory.attachComments(urlExpression, [o.leadingComment(ast.urlComment, true)]);
|
||||
}
|
||||
return this.factory.createDynamicImport(urlExpression);
|
||||
}
|
||||
visitNotExpr(ast, context) {
|
||||
return this.factory.createUnaryExpression("!", ast.condition.visitExpression(this, context));
|
||||
}
|
||||
visitFunctionExpr(ast, context) {
|
||||
return this.factory.createFunctionExpression(ast.name ?? null, ast.params.map((param) => param.name), this.factory.createBlock(this.visitStatements(ast.statements, context)));
|
||||
}
|
||||
visitArrowFunctionExpr(ast, context) {
|
||||
return this.factory.createArrowFunctionExpression(ast.params.map((param) => param.name), Array.isArray(ast.body) ? this.factory.createBlock(this.visitStatements(ast.body, context)) : ast.body.visitExpression(this, context));
|
||||
}
|
||||
visitBinaryOperatorExpr(ast, context) {
|
||||
if (!BINARY_OPERATORS.has(ast.operator)) {
|
||||
throw new Error(`Unknown binary operator: ${o.BinaryOperator[ast.operator]}`);
|
||||
}
|
||||
const operator = BINARY_OPERATORS.get(ast.operator);
|
||||
if (ast.isAssignment()) {
|
||||
return this.factory.createAssignment(ast.lhs.visitExpression(this, context), operator, ast.rhs.visitExpression(this, context));
|
||||
}
|
||||
return this.factory.createBinaryExpression(ast.lhs.visitExpression(this, context), operator, ast.rhs.visitExpression(this, context));
|
||||
}
|
||||
visitReadPropExpr(ast, context) {
|
||||
return this.factory.createPropertyAccess(ast.receiver.visitExpression(this, context), ast.name);
|
||||
}
|
||||
visitReadKeyExpr(ast, context) {
|
||||
return this.factory.createElementAccess(ast.receiver.visitExpression(this, context), ast.index.visitExpression(this, context));
|
||||
}
|
||||
visitLiteralArrayExpr(ast, context) {
|
||||
return this.factory.createArrayLiteral(ast.entries.map((expr) => this.setSourceMapRange(expr.visitExpression(this, context), ast.sourceSpan)));
|
||||
}
|
||||
visitLiteralMapExpr(ast, context) {
|
||||
const properties = ast.entries.map((entry) => {
|
||||
return entry instanceof o.LiteralMapPropertyAssignment ? {
|
||||
kind: "property",
|
||||
propertyName: entry.key,
|
||||
quoted: entry.quoted,
|
||||
value: entry.value.visitExpression(this, context)
|
||||
} : {
|
||||
kind: "spread",
|
||||
expression: entry.expression.visitExpression(this, context)
|
||||
};
|
||||
});
|
||||
return this.setSourceMapRange(this.factory.createObjectLiteral(properties), ast.sourceSpan);
|
||||
}
|
||||
visitCommaExpr(ast, context) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
visitTemplateLiteralElementExpr(ast, context) {
|
||||
throw new Error("Method not implemented");
|
||||
}
|
||||
visitSpreadElementExpr(ast, context) {
|
||||
const expression = ast.expression.visitExpression(this, context);
|
||||
return this.setSourceMapRange(this.factory.createSpreadElement(expression), ast.sourceSpan);
|
||||
}
|
||||
visitWrappedNodeExpr(ast, _context) {
|
||||
this.recordWrappedNode(ast);
|
||||
return ast.node;
|
||||
}
|
||||
visitTypeofExpr(ast, context) {
|
||||
return this.factory.createTypeOfExpression(ast.expr.visitExpression(this, context));
|
||||
}
|
||||
visitVoidExpr(ast, context) {
|
||||
return this.factory.createVoidExpression(ast.expr.visitExpression(this, context));
|
||||
}
|
||||
visitUnaryOperatorExpr(ast, context) {
|
||||
if (!UNARY_OPERATORS.has(ast.operator)) {
|
||||
throw new Error(`Unknown unary operator: ${o.UnaryOperator[ast.operator]}`);
|
||||
}
|
||||
return this.factory.createUnaryExpression(UNARY_OPERATORS.get(ast.operator), ast.expr.visitExpression(this, context));
|
||||
}
|
||||
visitParenthesizedExpr(ast, context) {
|
||||
const result = ast.expr.visitExpression(this, context);
|
||||
return this.factory.createParenthesizedExpression(result);
|
||||
}
|
||||
visitStatements(statements, context) {
|
||||
return statements.map((stmt) => stmt.visitStatement(this, context)).filter((stmt) => stmt !== void 0);
|
||||
}
|
||||
setSourceMapRange(ast, span) {
|
||||
return this.factory.setSourceMapRange(ast, createRange(span));
|
||||
}
|
||||
attachComments(statement, leadingComments) {
|
||||
if (leadingComments !== void 0) {
|
||||
this.factory.attachComments(statement, leadingComments);
|
||||
}
|
||||
return statement;
|
||||
}
|
||||
getTemplateLiteralFromAst(ast, context) {
|
||||
return {
|
||||
elements: ast.elements.map((e) => createTemplateElement({
|
||||
cooked: e.text,
|
||||
raw: e.rawText,
|
||||
range: e.sourceSpan ?? ast.sourceSpan
|
||||
})),
|
||||
expressions: ast.expressions.map((e) => e.visitExpression(this, context))
|
||||
};
|
||||
}
|
||||
};
|
||||
function createTemplateElement({ cooked, raw, range }) {
|
||||
return { cooked, raw, range: createRange(range) };
|
||||
}
|
||||
function createRange(span) {
|
||||
if (span === null) {
|
||||
return null;
|
||||
}
|
||||
const { start, end } = span;
|
||||
const { url, content } = start.file;
|
||||
if (!url) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
url,
|
||||
content,
|
||||
start: { offset: start.offset, line: start.line, column: start.col },
|
||||
end: { offset: end.offset, line: end.line, column: end.col }
|
||||
};
|
||||
}
|
||||
|
||||
export {
|
||||
Context,
|
||||
ExpressionTranslatorVisitor
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+1365
File diff suppressed because it is too large
Load Diff
+15
@@ -0,0 +1,15 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
||||
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
||||
}) : x)(function(x) {
|
||||
if (typeof require !== "undefined")
|
||||
return require.apply(this, arguments);
|
||||
throw Error('Dynamic require of "' + x + '" is not supported');
|
||||
});
|
||||
|
||||
export {
|
||||
__require
|
||||
};
|
||||
+542
@@ -0,0 +1,542 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file.js
|
||||
import { decode, encode } from "@jridgewell/sourcemap-codec";
|
||||
import mapHelpers from "convert-source-map";
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/sourcemaps/src/segment_marker.js
|
||||
function compareSegments(a, b) {
|
||||
return a.position - b.position;
|
||||
}
|
||||
function offsetSegment(startOfLinePositions, marker, offset) {
|
||||
if (offset === 0) {
|
||||
return marker;
|
||||
}
|
||||
let line = marker.line;
|
||||
const position = marker.position + offset;
|
||||
while (line < startOfLinePositions.length - 1 && startOfLinePositions[line + 1] <= position) {
|
||||
line++;
|
||||
}
|
||||
while (line > 0 && startOfLinePositions[line] > position) {
|
||||
line--;
|
||||
}
|
||||
const column = position - startOfLinePositions[line];
|
||||
return { line, column, position, next: void 0 };
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file.js
|
||||
function removeSourceMapComments(contents) {
|
||||
return mapHelpers.removeMapFileComments(mapHelpers.removeComments(contents)).replace(/\n\n$/, "\n");
|
||||
}
|
||||
var SourceFile = class {
|
||||
sourcePath;
|
||||
contents;
|
||||
rawMap;
|
||||
sources;
|
||||
fs;
|
||||
/**
|
||||
* The parsed mappings that have been flattened so that any intermediate source mappings have been
|
||||
* flattened.
|
||||
*
|
||||
* The result is that any source file mentioned in the flattened mappings have no source map (are
|
||||
* pure original source files).
|
||||
*/
|
||||
flattenedMappings;
|
||||
startOfLinePositions;
|
||||
constructor(sourcePath, contents, rawMap, sources, fs) {
|
||||
this.sourcePath = sourcePath;
|
||||
this.contents = contents;
|
||||
this.rawMap = rawMap;
|
||||
this.sources = sources;
|
||||
this.fs = fs;
|
||||
this.contents = removeSourceMapComments(contents);
|
||||
this.startOfLinePositions = computeStartOfLinePositions(this.contents);
|
||||
this.flattenedMappings = this.flattenMappings();
|
||||
}
|
||||
/**
|
||||
* Render the raw source map generated from the flattened mappings.
|
||||
*/
|
||||
renderFlattenedSourceMap() {
|
||||
const sources = new IndexedMap();
|
||||
const names = new IndexedSet();
|
||||
const mappings = [];
|
||||
const sourcePathDir = this.fs.dirname(this.sourcePath);
|
||||
const relativeSourcePathCache = new Cache((input) => this.fs.relative(sourcePathDir, input));
|
||||
for (const mapping of this.flattenedMappings) {
|
||||
const sourceIndex = sources.set(relativeSourcePathCache.get(mapping.originalSource.sourcePath), mapping.originalSource.contents);
|
||||
const mappingArray = [
|
||||
mapping.generatedSegment.column,
|
||||
sourceIndex,
|
||||
mapping.originalSegment.line,
|
||||
mapping.originalSegment.column
|
||||
];
|
||||
if (mapping.name !== void 0) {
|
||||
const nameIndex = names.add(mapping.name);
|
||||
mappingArray.push(nameIndex);
|
||||
}
|
||||
const line = mapping.generatedSegment.line;
|
||||
while (line >= mappings.length) {
|
||||
mappings.push([]);
|
||||
}
|
||||
mappings[line].push(mappingArray);
|
||||
}
|
||||
const sourceMap = {
|
||||
version: 3,
|
||||
file: this.fs.relative(sourcePathDir, this.sourcePath),
|
||||
sources: sources.keys,
|
||||
names: names.values,
|
||||
mappings: encode(mappings),
|
||||
sourcesContent: sources.values
|
||||
};
|
||||
return sourceMap;
|
||||
}
|
||||
/**
|
||||
* Find the original mapped location for the given `line` and `column` in the generated file.
|
||||
*
|
||||
* First we search for a mapping whose generated segment is at or directly before the given
|
||||
* location. Then we compute the offset between the given location and the matching generated
|
||||
* segment. Finally we apply this offset to the original source segment to get the desired
|
||||
* original location.
|
||||
*/
|
||||
getOriginalLocation(line, column) {
|
||||
if (this.flattenedMappings.length === 0) {
|
||||
return null;
|
||||
}
|
||||
let position;
|
||||
if (line < this.startOfLinePositions.length) {
|
||||
position = this.startOfLinePositions[line] + column;
|
||||
} else {
|
||||
position = this.contents.length;
|
||||
}
|
||||
const locationSegment = { line, column, position, next: void 0 };
|
||||
let mappingIndex = findLastMappingIndexBefore(this.flattenedMappings, locationSegment, false, 0);
|
||||
if (mappingIndex < 0) {
|
||||
mappingIndex = 0;
|
||||
}
|
||||
const { originalSegment, originalSource, generatedSegment } = this.flattenedMappings[mappingIndex];
|
||||
const offset = locationSegment.position - generatedSegment.position;
|
||||
const offsetOriginalSegment = offsetSegment(originalSource.startOfLinePositions, originalSegment, offset);
|
||||
return {
|
||||
file: originalSource.sourcePath,
|
||||
line: offsetOriginalSegment.line,
|
||||
column: offsetOriginalSegment.column
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Flatten the parsed mappings for this source file, so that all the mappings are to pure original
|
||||
* source files with no transitive source maps.
|
||||
*/
|
||||
flattenMappings() {
|
||||
const mappings = parseMappings(this.rawMap && this.rawMap.map, this.sources, this.startOfLinePositions);
|
||||
ensureOriginalSegmentLinks(mappings);
|
||||
const flattenedMappings = [];
|
||||
for (let mappingIndex = 0; mappingIndex < mappings.length; mappingIndex++) {
|
||||
const aToBmapping = mappings[mappingIndex];
|
||||
const bSource = aToBmapping.originalSource;
|
||||
if (bSource.flattenedMappings.length === 0) {
|
||||
flattenedMappings.push(aToBmapping);
|
||||
continue;
|
||||
}
|
||||
const incomingStart = aToBmapping.originalSegment;
|
||||
const incomingEnd = incomingStart.next;
|
||||
let outgoingStartIndex = findLastMappingIndexBefore(bSource.flattenedMappings, incomingStart, false, 0);
|
||||
if (outgoingStartIndex < 0) {
|
||||
outgoingStartIndex = 0;
|
||||
}
|
||||
const outgoingEndIndex = incomingEnd !== void 0 ? findLastMappingIndexBefore(bSource.flattenedMappings, incomingEnd, true, outgoingStartIndex) : bSource.flattenedMappings.length - 1;
|
||||
for (let bToCmappingIndex = outgoingStartIndex; bToCmappingIndex <= outgoingEndIndex; bToCmappingIndex++) {
|
||||
const bToCmapping = bSource.flattenedMappings[bToCmappingIndex];
|
||||
flattenedMappings.push(mergeMappings(this, aToBmapping, bToCmapping));
|
||||
}
|
||||
}
|
||||
return flattenedMappings;
|
||||
}
|
||||
};
|
||||
function findLastMappingIndexBefore(mappings, marker, exclusive, lowerIndex) {
|
||||
let upperIndex = mappings.length - 1;
|
||||
const test = exclusive ? -1 : 0;
|
||||
if (compareSegments(mappings[lowerIndex].generatedSegment, marker) > test) {
|
||||
return -1;
|
||||
}
|
||||
let matchingIndex = -1;
|
||||
while (lowerIndex <= upperIndex) {
|
||||
const index = upperIndex + lowerIndex >> 1;
|
||||
if (compareSegments(mappings[index].generatedSegment, marker) <= test) {
|
||||
matchingIndex = index;
|
||||
lowerIndex = index + 1;
|
||||
} else {
|
||||
upperIndex = index - 1;
|
||||
}
|
||||
}
|
||||
return matchingIndex;
|
||||
}
|
||||
function mergeMappings(generatedSource, ab, bc) {
|
||||
const name = bc.name || ab.name;
|
||||
const diff = compareSegments(bc.generatedSegment, ab.originalSegment);
|
||||
if (diff > 0) {
|
||||
return {
|
||||
name,
|
||||
generatedSegment: offsetSegment(generatedSource.startOfLinePositions, ab.generatedSegment, diff),
|
||||
originalSource: bc.originalSource,
|
||||
originalSegment: bc.originalSegment
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
name,
|
||||
generatedSegment: ab.generatedSegment,
|
||||
originalSource: bc.originalSource,
|
||||
originalSegment: offsetSegment(bc.originalSource.startOfLinePositions, bc.originalSegment, -diff)
|
||||
};
|
||||
}
|
||||
}
|
||||
function parseMappings(rawMap, sources, generatedSourceStartOfLinePositions) {
|
||||
if (rawMap === null) {
|
||||
return [];
|
||||
}
|
||||
const rawMappings = decode(rawMap.mappings);
|
||||
if (rawMappings === null) {
|
||||
return [];
|
||||
}
|
||||
const mappings = [];
|
||||
for (let generatedLine = 0; generatedLine < rawMappings.length; generatedLine++) {
|
||||
const generatedLineMappings = rawMappings[generatedLine];
|
||||
for (const rawMapping of generatedLineMappings) {
|
||||
if (rawMapping.length >= 4) {
|
||||
const originalSource = sources[rawMapping[1]];
|
||||
if (originalSource === null || originalSource === void 0) {
|
||||
continue;
|
||||
}
|
||||
const generatedColumn = rawMapping[0];
|
||||
const name = rawMapping.length === 5 ? rawMap.names[rawMapping[4]] : void 0;
|
||||
const line = rawMapping[2];
|
||||
const column = rawMapping[3];
|
||||
const generatedSegment = {
|
||||
line: generatedLine,
|
||||
column: generatedColumn,
|
||||
position: generatedSourceStartOfLinePositions[generatedLine] + generatedColumn,
|
||||
next: void 0
|
||||
};
|
||||
const originalSegment = {
|
||||
line,
|
||||
column,
|
||||
position: originalSource.startOfLinePositions[line] + column,
|
||||
next: void 0
|
||||
};
|
||||
mappings.push({ name, generatedSegment, originalSegment, originalSource });
|
||||
}
|
||||
}
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
function extractOriginalSegments(mappings) {
|
||||
const originalSegments = /* @__PURE__ */ new Map();
|
||||
for (const mapping of mappings) {
|
||||
const originalSource = mapping.originalSource;
|
||||
if (!originalSegments.has(originalSource)) {
|
||||
originalSegments.set(originalSource, []);
|
||||
}
|
||||
const segments = originalSegments.get(originalSource);
|
||||
segments.push(mapping.originalSegment);
|
||||
}
|
||||
originalSegments.forEach((segmentMarkers) => segmentMarkers.sort(compareSegments));
|
||||
return originalSegments;
|
||||
}
|
||||
function ensureOriginalSegmentLinks(mappings) {
|
||||
const segmentsBySource = extractOriginalSegments(mappings);
|
||||
segmentsBySource.forEach((markers) => {
|
||||
for (let i = 0; i < markers.length - 1; i++) {
|
||||
markers[i].next = markers[i + 1];
|
||||
}
|
||||
});
|
||||
}
|
||||
function computeStartOfLinePositions(str) {
|
||||
const NEWLINE_MARKER_OFFSET = 1;
|
||||
const lineLengths = computeLineLengths(str);
|
||||
const startPositions = [0];
|
||||
for (let i = 0; i < lineLengths.length - 1; i++) {
|
||||
startPositions.push(startPositions[i] + lineLengths[i] + NEWLINE_MARKER_OFFSET);
|
||||
}
|
||||
return startPositions;
|
||||
}
|
||||
function computeLineLengths(str) {
|
||||
return str.split(/\n/).map((s) => s.length);
|
||||
}
|
||||
var IndexedMap = class {
|
||||
map = /* @__PURE__ */ new Map();
|
||||
/**
|
||||
* An array of keys added to this map.
|
||||
*
|
||||
* This array is guaranteed to be in the order of the first time the key was added to the map.
|
||||
*/
|
||||
keys = [];
|
||||
/**
|
||||
* An array of values added to this map.
|
||||
*
|
||||
* This array is guaranteed to be in the order of the first time the associated key was added to
|
||||
* the map.
|
||||
*/
|
||||
values = [];
|
||||
/**
|
||||
* Associate the `value` with the `key` and return the index of the key in the collection.
|
||||
*
|
||||
* If the `key` already exists then the `value` is not set and the index of that `key` is
|
||||
* returned; otherwise the `key` and `value` are stored and the index of the new `key` is
|
||||
* returned.
|
||||
*
|
||||
* @param key the key to associated with the `value`.
|
||||
* @param value the value to associated with the `key`.
|
||||
* @returns the index of the `key` in the `keys` array.
|
||||
*/
|
||||
set(key, value) {
|
||||
if (this.map.has(key)) {
|
||||
return this.map.get(key);
|
||||
}
|
||||
const index = this.values.push(value) - 1;
|
||||
this.keys.push(key);
|
||||
this.map.set(key, index);
|
||||
return index;
|
||||
}
|
||||
};
|
||||
var IndexedSet = class {
|
||||
map = /* @__PURE__ */ new Map();
|
||||
/**
|
||||
* An array of values added to this set.
|
||||
* This array is guaranteed to be in the order of the first time the value was added to the set.
|
||||
*/
|
||||
values = [];
|
||||
/**
|
||||
* Add the `value` to the `values` array, if it doesn't already exist; returning the index of the
|
||||
* `value` in the `values` array.
|
||||
*
|
||||
* If the `value` already exists then the index of that `value` is returned, otherwise the new
|
||||
* `value` is stored and the new index returned.
|
||||
*
|
||||
* @param value the value to add to the set.
|
||||
* @returns the index of the `value` in the `values` array.
|
||||
*/
|
||||
add(value) {
|
||||
if (this.map.has(value)) {
|
||||
return this.map.get(value);
|
||||
}
|
||||
const index = this.values.push(value) - 1;
|
||||
this.map.set(value, index);
|
||||
return index;
|
||||
}
|
||||
};
|
||||
var Cache = class {
|
||||
computeFn;
|
||||
map = /* @__PURE__ */ new Map();
|
||||
constructor(computeFn) {
|
||||
this.computeFn = computeFn;
|
||||
}
|
||||
get(input) {
|
||||
if (!this.map.has(input)) {
|
||||
this.map.set(input, this.computeFn(input));
|
||||
}
|
||||
return this.map.get(input);
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file_loader.js
|
||||
import mapHelpers2 from "convert-source-map";
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/sourcemaps/src/content_origin.js
|
||||
var ContentOrigin;
|
||||
(function(ContentOrigin2) {
|
||||
ContentOrigin2[ContentOrigin2["Provided"] = 0] = "Provided";
|
||||
ContentOrigin2[ContentOrigin2["Inline"] = 1] = "Inline";
|
||||
ContentOrigin2[ContentOrigin2["FileSystem"] = 2] = "FileSystem";
|
||||
})(ContentOrigin || (ContentOrigin = {}));
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/sourcemaps/src/source_file_loader.js
|
||||
var SCHEME_MATCHER = /^([a-z][a-z0-9.-]*):\/\//i;
|
||||
var SourceFileLoader = class {
|
||||
fs;
|
||||
logger;
|
||||
schemeMap;
|
||||
currentPaths = [];
|
||||
constructor(fs, logger, schemeMap) {
|
||||
this.fs = fs;
|
||||
this.logger = logger;
|
||||
this.schemeMap = schemeMap;
|
||||
}
|
||||
loadSourceFile(sourcePath, contents = null, mapAndPath = null) {
|
||||
const contentsOrigin = contents !== null ? ContentOrigin.Provided : ContentOrigin.FileSystem;
|
||||
const sourceMapInfo = mapAndPath && {
|
||||
origin: ContentOrigin.Provided,
|
||||
...mapAndPath
|
||||
};
|
||||
return this.loadSourceFileInternal(sourcePath, contents, contentsOrigin, sourceMapInfo);
|
||||
}
|
||||
/**
|
||||
* The overload used internally to load source files referenced in a source-map.
|
||||
*
|
||||
* In this case there is no guarantee that it will return a non-null SourceMap.
|
||||
*
|
||||
* @param sourcePath The path to the source file to load.
|
||||
* @param contents The contents of the source file to load, if provided inline. If `null`,
|
||||
* the contents will be read from the file at the `sourcePath`.
|
||||
* @param sourceOrigin Describes where the source content came from.
|
||||
* @param sourceMapInfo The raw contents and path of the source-map file. If `null` the
|
||||
* source-map will be computed from the contents of the source file, either inline or loaded
|
||||
* from the file-system.
|
||||
*
|
||||
* @returns a SourceFile if the content for one was provided or was able to be loaded from disk,
|
||||
* `null` otherwise.
|
||||
*/
|
||||
loadSourceFileInternal(sourcePath, contents, sourceOrigin, sourceMapInfo) {
|
||||
const previousPaths = this.currentPaths.slice();
|
||||
try {
|
||||
if (contents === null) {
|
||||
if (!this.fs.exists(sourcePath)) {
|
||||
return null;
|
||||
}
|
||||
contents = this.readSourceFile(sourcePath);
|
||||
}
|
||||
if (sourceMapInfo === null) {
|
||||
sourceMapInfo = this.loadSourceMap(sourcePath, contents, sourceOrigin);
|
||||
}
|
||||
let sources = [];
|
||||
if (sourceMapInfo !== null) {
|
||||
const basePath = sourceMapInfo.mapPath || sourcePath;
|
||||
sources = this.processSources(basePath, sourceMapInfo);
|
||||
}
|
||||
return new SourceFile(sourcePath, contents, sourceMapInfo, sources, this.fs);
|
||||
} catch (e) {
|
||||
this.logger.warn(`Unable to fully load ${sourcePath} for source-map flattening: ${e.message}`);
|
||||
return null;
|
||||
} finally {
|
||||
this.currentPaths = previousPaths;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Find the source map associated with the source file whose `sourcePath` and `contents` are
|
||||
* provided.
|
||||
*
|
||||
* Source maps can be inline, as part of a base64 encoded comment, or external as a separate file
|
||||
* whose path is indicated in a comment or implied from the name of the source file itself.
|
||||
*
|
||||
* @param sourcePath the path to the source file.
|
||||
* @param sourceContents the contents of the source file.
|
||||
* @param sourceOrigin where the content of the source file came from.
|
||||
* @returns the parsed contents and path of the source-map, if loading was successful, null
|
||||
* otherwise.
|
||||
*/
|
||||
loadSourceMap(sourcePath, sourceContents, sourceOrigin) {
|
||||
const lastLine = this.getLastNonEmptyLine(sourceContents);
|
||||
const inline = mapHelpers2.commentRegex.exec(lastLine);
|
||||
if (inline !== null) {
|
||||
return {
|
||||
map: mapHelpers2.fromComment(inline.pop()).sourcemap,
|
||||
mapPath: null,
|
||||
origin: ContentOrigin.Inline
|
||||
};
|
||||
}
|
||||
if (sourceOrigin === ContentOrigin.Inline) {
|
||||
return null;
|
||||
}
|
||||
const external = mapHelpers2.mapFileCommentRegex.exec(lastLine);
|
||||
if (external) {
|
||||
try {
|
||||
const fileName = external[1] || external[2];
|
||||
const externalMapPath = this.fs.resolve(this.fs.dirname(sourcePath), fileName);
|
||||
return {
|
||||
map: this.readRawSourceMap(externalMapPath),
|
||||
mapPath: externalMapPath,
|
||||
origin: ContentOrigin.FileSystem
|
||||
};
|
||||
} catch (e) {
|
||||
this.logger.warn(`Unable to fully load ${sourcePath} for source-map flattening: ${e.message}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const impliedMapPath = this.fs.resolve(sourcePath + ".map");
|
||||
if (this.fs.exists(impliedMapPath)) {
|
||||
return {
|
||||
map: this.readRawSourceMap(impliedMapPath),
|
||||
mapPath: impliedMapPath,
|
||||
origin: ContentOrigin.FileSystem
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Iterate over each of the "sources" for this source file's source map, recursively loading each
|
||||
* source file and its associated source map.
|
||||
*/
|
||||
processSources(basePath, { map, origin: sourceMapOrigin }) {
|
||||
const sourceRoot = this.fs.resolve(this.fs.dirname(basePath), this.replaceSchemeWithPath(map.sourceRoot || ""));
|
||||
return map.sources.map((source, index) => {
|
||||
const path = this.fs.resolve(sourceRoot, this.replaceSchemeWithPath(source));
|
||||
const content = map.sourcesContent && map.sourcesContent[index] || null;
|
||||
const sourceOrigin = content !== null && sourceMapOrigin !== ContentOrigin.Provided ? ContentOrigin.Inline : ContentOrigin.FileSystem;
|
||||
return this.loadSourceFileInternal(path, content, sourceOrigin, null);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Load the contents of the source file from disk.
|
||||
*
|
||||
* @param sourcePath The path to the source file.
|
||||
*/
|
||||
readSourceFile(sourcePath) {
|
||||
this.trackPath(sourcePath);
|
||||
return this.fs.readFile(sourcePath);
|
||||
}
|
||||
/**
|
||||
* Load the source map from the file at `mapPath`, parsing its JSON contents into a `RawSourceMap`
|
||||
* object.
|
||||
*
|
||||
* @param mapPath The path to the source-map file.
|
||||
*/
|
||||
readRawSourceMap(mapPath) {
|
||||
this.trackPath(mapPath);
|
||||
return JSON.parse(this.fs.readFile(mapPath));
|
||||
}
|
||||
/**
|
||||
* Track source file paths if we have loaded them from disk so that we don't get into an infinite
|
||||
* recursion.
|
||||
*/
|
||||
trackPath(path) {
|
||||
if (this.currentPaths.includes(path)) {
|
||||
throw new Error(`Circular source file mapping dependency: ${this.currentPaths.join(" -> ")} -> ${path}`);
|
||||
}
|
||||
this.currentPaths.push(path);
|
||||
}
|
||||
getLastNonEmptyLine(contents) {
|
||||
let trailingWhitespaceIndex = contents.length - 1;
|
||||
while (trailingWhitespaceIndex > 0 && (contents[trailingWhitespaceIndex] === "\n" || contents[trailingWhitespaceIndex] === "\r")) {
|
||||
trailingWhitespaceIndex--;
|
||||
}
|
||||
let lastRealLineIndex = contents.lastIndexOf("\n", trailingWhitespaceIndex - 1);
|
||||
if (lastRealLineIndex === -1) {
|
||||
lastRealLineIndex = 0;
|
||||
}
|
||||
return contents.slice(lastRealLineIndex + 1);
|
||||
}
|
||||
/**
|
||||
* Replace any matched URL schemes with their corresponding path held in the schemeMap.
|
||||
*
|
||||
* Some build tools replace real file paths with scheme prefixed paths - e.g. `webpack://`.
|
||||
* We use the `schemeMap` passed to this class to convert such paths to "real" file paths.
|
||||
* In some cases, this is not possible, since the file was actually synthesized by the build tool.
|
||||
* But the end result is better than prefixing the sourceRoot in front of the scheme.
|
||||
*/
|
||||
replaceSchemeWithPath(path) {
|
||||
return path.replace(SCHEME_MATCHER, (_, scheme) => this.schemeMap[scheme.toLowerCase()] || "");
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
SourceFile,
|
||||
SourceFileLoader
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+23204
File diff suppressed because it is too large
Load Diff
+5376
File diff suppressed because it is too large
Load Diff
+644
@@ -0,0 +1,644 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
NgCompiler,
|
||||
NgCompilerHost,
|
||||
TrackedIncrementalBuildStrategy,
|
||||
freshCompilationTicket,
|
||||
incrementalFromCompilerTicket
|
||||
} from "./chunk-PW54LIP6.js";
|
||||
import {
|
||||
ActivePerfRecorder,
|
||||
OptimizeFor,
|
||||
PerfCheckpoint,
|
||||
PerfEvent,
|
||||
PerfPhase,
|
||||
TsCreateProgramDriver,
|
||||
replaceTsWithNgInErrors,
|
||||
retagAllTsFiles
|
||||
} from "./chunk-IG22BDVK.js";
|
||||
import {
|
||||
absoluteFrom,
|
||||
createFileSystemTsReadDirectoryFn,
|
||||
getFileSystem,
|
||||
resolve
|
||||
} from "./chunk-CEBE44Q5.js";
|
||||
|
||||
// packages/compiler-cli/src/transformers/api.js
|
||||
var DEFAULT_ERROR_CODE = 100;
|
||||
var UNKNOWN_ERROR_CODE = 500;
|
||||
var SOURCE = "angular";
|
||||
function isTsDiagnostic(diagnostic) {
|
||||
return diagnostic != null && diagnostic.source !== "angular";
|
||||
}
|
||||
var EmitFlags;
|
||||
(function(EmitFlags2) {
|
||||
EmitFlags2[EmitFlags2["DTS"] = 1] = "DTS";
|
||||
EmitFlags2[EmitFlags2["JS"] = 2] = "JS";
|
||||
EmitFlags2[EmitFlags2["Metadata"] = 4] = "Metadata";
|
||||
EmitFlags2[EmitFlags2["I18nBundle"] = 8] = "I18nBundle";
|
||||
EmitFlags2[EmitFlags2["Codegen"] = 16] = "Codegen";
|
||||
EmitFlags2[EmitFlags2["Default"] = 19] = "Default";
|
||||
EmitFlags2[EmitFlags2["All"] = 31] = "All";
|
||||
})(EmitFlags || (EmitFlags = {}));
|
||||
|
||||
// packages/compiler-cli/src/transformers/compiler_host.js
|
||||
import ts from "typescript";
|
||||
var wrapHostForTest = null;
|
||||
function createCompilerHost({ options, tsHost = ts.createCompilerHost(options, true) }) {
|
||||
if (wrapHostForTest !== null) {
|
||||
tsHost = wrapHostForTest(tsHost);
|
||||
}
|
||||
return tsHost;
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/program.js
|
||||
import { HtmlParser, MessageBundle } from "@angular/compiler";
|
||||
import ts3 from "typescript";
|
||||
|
||||
// packages/compiler-cli/src/transformers/i18n.js
|
||||
import { Xliff, Xliff2, Xmb } from "@angular/compiler";
|
||||
import * as path from "path";
|
||||
function i18nGetExtension(formatName) {
|
||||
const format = formatName.toLowerCase();
|
||||
switch (format) {
|
||||
case "xmb":
|
||||
return "xmb";
|
||||
case "xlf":
|
||||
case "xlif":
|
||||
case "xliff":
|
||||
case "xlf2":
|
||||
case "xliff2":
|
||||
return "xlf";
|
||||
}
|
||||
throw new Error(`Unsupported format "${formatName}"`);
|
||||
}
|
||||
function i18nExtract(formatName, outFile, host, options, bundle, pathResolve = path.resolve) {
|
||||
formatName = formatName || "xlf";
|
||||
const ext = i18nGetExtension(formatName);
|
||||
const content = i18nSerialize(bundle, formatName, options);
|
||||
const dstFile = outFile || `messages.${ext}`;
|
||||
const dstPath = pathResolve(options.outDir || options.basePath, dstFile);
|
||||
host.writeFile(dstPath, content, false, void 0, []);
|
||||
return [dstPath];
|
||||
}
|
||||
function i18nSerialize(bundle, formatName, options) {
|
||||
const format = formatName.toLowerCase();
|
||||
let serializer;
|
||||
switch (format) {
|
||||
case "xmb":
|
||||
serializer = new Xmb();
|
||||
break;
|
||||
case "xliff2":
|
||||
case "xlf2":
|
||||
serializer = new Xliff2();
|
||||
break;
|
||||
case "xlf":
|
||||
case "xliff":
|
||||
default:
|
||||
serializer = new Xliff();
|
||||
}
|
||||
return bundle.write(serializer, getPathNormalizer(options.basePath));
|
||||
}
|
||||
function getPathNormalizer(basePath) {
|
||||
return (sourcePath) => {
|
||||
sourcePath = basePath ? path.relative(basePath, sourcePath) : sourcePath;
|
||||
return sourcePath.split(path.sep).join("/");
|
||||
};
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/typescript_support.js
|
||||
import ts2 from "typescript";
|
||||
|
||||
// packages/compiler-cli/src/version_helpers.js
|
||||
function toNumbers(value) {
|
||||
const suffixIndex = value.lastIndexOf("-");
|
||||
return value.slice(0, suffixIndex === -1 ? value.length : suffixIndex).split(".").map((segment) => {
|
||||
const parsed = parseInt(segment, 10);
|
||||
if (isNaN(parsed)) {
|
||||
throw Error(`Unable to parse version string ${value}.`);
|
||||
}
|
||||
return parsed;
|
||||
});
|
||||
}
|
||||
function compareNumbers(a, b) {
|
||||
const max = Math.max(a.length, b.length);
|
||||
const min = Math.min(a.length, b.length);
|
||||
for (let i = 0; i < min; i++) {
|
||||
if (a[i] > b[i])
|
||||
return 1;
|
||||
if (a[i] < b[i])
|
||||
return -1;
|
||||
}
|
||||
if (min !== max) {
|
||||
const longestArray = a.length === max ? a : b;
|
||||
const comparisonResult = a.length === max ? 1 : -1;
|
||||
for (let i = min; i < max; i++) {
|
||||
if (longestArray[i] > 0) {
|
||||
return comparisonResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
function compareVersions(v1, v2) {
|
||||
return compareNumbers(toNumbers(v1), toNumbers(v2));
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/typescript_support.js
|
||||
var MIN_TS_VERSION = "5.9.0";
|
||||
var MAX_TS_VERSION = "6.1.0";
|
||||
var tsVersion = ts2.version;
|
||||
function checkVersion(version, minVersion, maxVersion) {
|
||||
if (compareVersions(version, minVersion) < 0 || compareVersions(version, maxVersion) >= 0) {
|
||||
throw new Error(`The Angular Compiler requires TypeScript >=${minVersion} and <${maxVersion} but ${version} was found instead.`);
|
||||
}
|
||||
}
|
||||
function verifySupportedTypeScriptVersion() {
|
||||
checkVersion(tsVersion, MIN_TS_VERSION, MAX_TS_VERSION);
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/program.js
|
||||
var NgtscProgram = class {
|
||||
options;
|
||||
compiler;
|
||||
/**
|
||||
* The primary TypeScript program, which is used for analysis and emit.
|
||||
*/
|
||||
tsProgram;
|
||||
host;
|
||||
incrementalStrategy;
|
||||
constructor(rootNames, options, delegateHost, oldProgram) {
|
||||
this.options = options;
|
||||
const perfRecorder = ActivePerfRecorder.zeroedToNow();
|
||||
perfRecorder.phase(PerfPhase.Setup);
|
||||
if (!options.disableTypeScriptVersionCheck) {
|
||||
verifySupportedTypeScriptVersion();
|
||||
}
|
||||
if (options.compilationMode === "experimental-local") {
|
||||
options.noEmitOnError = false;
|
||||
}
|
||||
const reuseProgram = oldProgram?.compiler.getCurrentProgram();
|
||||
this.host = NgCompilerHost.wrap(delegateHost, rootNames, options, reuseProgram ?? null);
|
||||
if (reuseProgram !== void 0) {
|
||||
retagAllTsFiles(reuseProgram);
|
||||
}
|
||||
this.tsProgram = perfRecorder.inPhase(PerfPhase.TypeScriptProgramCreate, () => ts3.createProgram(this.host.inputFiles, options, this.host, reuseProgram));
|
||||
perfRecorder.phase(PerfPhase.Unaccounted);
|
||||
perfRecorder.memory(PerfCheckpoint.TypeScriptProgramCreate);
|
||||
this.host.postProgramCreationCleanup();
|
||||
const programDriver = new TsCreateProgramDriver(this.tsProgram, this.host, this.options, this.host.shimExtensionPrefixes);
|
||||
this.incrementalStrategy = oldProgram !== void 0 ? oldProgram.incrementalStrategy.toNextBuildStrategy() : new TrackedIncrementalBuildStrategy();
|
||||
const modifiedResourceFiles = /* @__PURE__ */ new Set();
|
||||
if (this.host.getModifiedResourceFiles !== void 0) {
|
||||
const strings = this.host.getModifiedResourceFiles();
|
||||
if (strings !== void 0) {
|
||||
for (const fileString of strings) {
|
||||
modifiedResourceFiles.add(absoluteFrom(fileString));
|
||||
}
|
||||
}
|
||||
}
|
||||
let ticket;
|
||||
if (oldProgram === void 0) {
|
||||
ticket = freshCompilationTicket(
|
||||
this.tsProgram,
|
||||
options,
|
||||
this.incrementalStrategy,
|
||||
programDriver,
|
||||
perfRecorder,
|
||||
/* enableTemplateTypeChecker */
|
||||
false,
|
||||
/* usePoisonedData */
|
||||
false
|
||||
);
|
||||
} else {
|
||||
ticket = incrementalFromCompilerTicket(oldProgram.compiler, this.tsProgram, this.incrementalStrategy, programDriver, modifiedResourceFiles, perfRecorder);
|
||||
}
|
||||
this.compiler = NgCompiler.fromTicket(ticket, this.host);
|
||||
}
|
||||
getTsProgram() {
|
||||
return this.tsProgram;
|
||||
}
|
||||
getReuseTsProgram() {
|
||||
return this.compiler.getCurrentProgram();
|
||||
}
|
||||
getTsOptionDiagnostics(cancellationToken) {
|
||||
return this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptDiagnostics, () => this.tsProgram.getOptionsDiagnostics(cancellationToken));
|
||||
}
|
||||
getTsSyntacticDiagnostics(sourceFile, cancellationToken) {
|
||||
return this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptDiagnostics, () => {
|
||||
const ignoredFiles = this.compiler.ignoreForDiagnostics;
|
||||
let res;
|
||||
if (sourceFile !== void 0) {
|
||||
if (ignoredFiles.has(sourceFile)) {
|
||||
return [];
|
||||
}
|
||||
res = this.tsProgram.getSyntacticDiagnostics(sourceFile, cancellationToken);
|
||||
} else {
|
||||
const diagnostics = [];
|
||||
for (const sf of this.tsProgram.getSourceFiles()) {
|
||||
if (!ignoredFiles.has(sf)) {
|
||||
diagnostics.push(...this.tsProgram.getSyntacticDiagnostics(sf, cancellationToken));
|
||||
}
|
||||
}
|
||||
res = diagnostics;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
}
|
||||
getTsSemanticDiagnostics(sourceFile, cancellationToken) {
|
||||
if (this.options.compilationMode === "experimental-local") {
|
||||
return [];
|
||||
}
|
||||
return this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptDiagnostics, () => {
|
||||
const ignoredFiles = this.compiler.ignoreForDiagnostics;
|
||||
let res;
|
||||
if (sourceFile !== void 0) {
|
||||
if (ignoredFiles.has(sourceFile)) {
|
||||
return [];
|
||||
}
|
||||
res = this.tsProgram.getSemanticDiagnostics(sourceFile, cancellationToken);
|
||||
} else {
|
||||
const diagnostics = [];
|
||||
for (const sf of this.tsProgram.getSourceFiles()) {
|
||||
if (!ignoredFiles.has(sf)) {
|
||||
diagnostics.push(...this.tsProgram.getSemanticDiagnostics(sf, cancellationToken));
|
||||
}
|
||||
}
|
||||
res = diagnostics;
|
||||
}
|
||||
return res;
|
||||
});
|
||||
}
|
||||
getNgOptionDiagnostics(cancellationToken) {
|
||||
return this.compiler.getOptionDiagnostics();
|
||||
}
|
||||
getNgStructuralDiagnostics(cancellationToken) {
|
||||
return [];
|
||||
}
|
||||
getNgSemanticDiagnostics(fileName, cancellationToken) {
|
||||
let sf = void 0;
|
||||
if (fileName !== void 0) {
|
||||
sf = this.tsProgram.getSourceFile(fileName);
|
||||
if (sf === void 0) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if (sf === void 0) {
|
||||
return this.compiler.getDiagnostics();
|
||||
} else {
|
||||
return this.compiler.getDiagnosticsForFile(sf, OptimizeFor.WholeProgram);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Ensure that the `NgCompiler` has properly analyzed the program, and allow for the asynchronous
|
||||
* loading of any resources during the process.
|
||||
*
|
||||
* This is used by the Angular CLI to allow for spawning (async) child compilations for things
|
||||
* like SASS files used in `styleUrls`.
|
||||
*/
|
||||
loadNgStructureAsync() {
|
||||
return this.compiler.analyzeAsync();
|
||||
}
|
||||
listLazyRoutes(entryRoute) {
|
||||
return [];
|
||||
}
|
||||
emitXi18n() {
|
||||
const ctx = new MessageBundle(new HtmlParser(), [], {}, this.options.i18nOutLocale ?? null, this.options.i18nPreserveWhitespaceForLegacyExtraction);
|
||||
this.compiler.xi18n(ctx);
|
||||
i18nExtract(this.options.i18nOutFormat ?? null, this.options.i18nOutFile ?? null, this.host, this.options, ctx, resolve);
|
||||
}
|
||||
emit(opts) {
|
||||
if (opts !== void 0 && opts.emitFlags !== void 0 && opts.emitFlags & EmitFlags.I18nBundle) {
|
||||
this.emitXi18n();
|
||||
if (!(opts.emitFlags & EmitFlags.JS)) {
|
||||
return {
|
||||
diagnostics: [],
|
||||
emitSkipped: true,
|
||||
emittedFiles: []
|
||||
};
|
||||
}
|
||||
}
|
||||
const forceEmit = opts?.forceEmit ?? false;
|
||||
this.compiler.perfRecorder.memory(PerfCheckpoint.PreEmit);
|
||||
const res = this.compiler.perfRecorder.inPhase(PerfPhase.TypeScriptEmit, () => {
|
||||
const { transformers } = this.compiler.prepareEmit();
|
||||
const ignoreFiles = this.compiler.ignoreForEmit;
|
||||
const emitCallback = opts?.emitCallback ?? defaultEmitCallback;
|
||||
const writeFile = (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
||||
if (sourceFiles !== void 0) {
|
||||
for (const writtenSf of sourceFiles) {
|
||||
if (writtenSf.isDeclarationFile) {
|
||||
continue;
|
||||
}
|
||||
this.compiler.incrementalCompilation.recordSuccessfulEmit(writtenSf);
|
||||
}
|
||||
}
|
||||
this.host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
||||
};
|
||||
const customTransforms = opts && opts.customTransformers;
|
||||
const beforeTransforms = transformers.before || [];
|
||||
const afterDeclarationsTransforms = transformers.afterDeclarations;
|
||||
if (customTransforms !== void 0 && customTransforms.beforeTs !== void 0) {
|
||||
beforeTransforms.push(...customTransforms.beforeTs);
|
||||
}
|
||||
const emitResults = [];
|
||||
for (const targetSourceFile of this.tsProgram.getSourceFiles()) {
|
||||
if (targetSourceFile.isDeclarationFile || ignoreFiles.has(targetSourceFile)) {
|
||||
continue;
|
||||
}
|
||||
if (!forceEmit && this.compiler.incrementalCompilation.safeToSkipEmit(targetSourceFile)) {
|
||||
this.compiler.perfRecorder.eventCount(PerfEvent.EmitSkipSourceFile);
|
||||
continue;
|
||||
}
|
||||
this.compiler.perfRecorder.eventCount(PerfEvent.EmitSourceFile);
|
||||
emitResults.push(emitCallback({
|
||||
targetSourceFile,
|
||||
program: this.tsProgram,
|
||||
host: this.host,
|
||||
options: this.options,
|
||||
emitOnlyDtsFiles: false,
|
||||
writeFile,
|
||||
customTransformers: {
|
||||
before: beforeTransforms,
|
||||
after: customTransforms && customTransforms.afterTs,
|
||||
afterDeclarations: afterDeclarationsTransforms
|
||||
}
|
||||
}));
|
||||
}
|
||||
this.compiler.perfRecorder.memory(PerfCheckpoint.Emit);
|
||||
return (opts && opts.mergeEmitResultsCallback || mergeEmitResults)(emitResults);
|
||||
});
|
||||
if (this.options.tracePerformance !== void 0) {
|
||||
const perf = this.compiler.perfRecorder.finalize();
|
||||
getFileSystem().writeFile(getFileSystem().resolve(this.options.tracePerformance), JSON.stringify(perf, null, 2));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
getIndexedComponents() {
|
||||
return this.compiler.getIndexedComponents();
|
||||
}
|
||||
/**
|
||||
* Gets information for the current program that may be used to generate API
|
||||
* reference documentation. This includes Angular-specific information, such
|
||||
* as component inputs and outputs.
|
||||
*
|
||||
* @param entryPoint Path to the entry point for the package for which API
|
||||
* docs should be extracted.
|
||||
*/
|
||||
getApiDocumentation(entryPoint, privateModules) {
|
||||
return this.compiler.getApiDocumentation(entryPoint, privateModules);
|
||||
}
|
||||
getEmittedSourceFiles() {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
};
|
||||
var defaultEmitCallback = ({ program, targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers }) => program.emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
|
||||
function mergeEmitResults(emitResults) {
|
||||
const diagnostics = [];
|
||||
let emitSkipped = false;
|
||||
const emittedFiles = [];
|
||||
for (const er of emitResults) {
|
||||
diagnostics.push(...er.diagnostics);
|
||||
emitSkipped = emitSkipped || er.emitSkipped;
|
||||
emittedFiles.push(...er.emittedFiles || []);
|
||||
}
|
||||
return { diagnostics, emitSkipped, emittedFiles };
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/transformers/program.js
|
||||
function createProgram({ rootNames, options, host, oldProgram }) {
|
||||
return new NgtscProgram(rootNames, options, host, oldProgram);
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/perform_compile.js
|
||||
import ts5 from "typescript";
|
||||
|
||||
// packages/compiler-cli/src/transformers/util.js
|
||||
import ts4 from "typescript";
|
||||
function createMessageDiagnostic(messageText) {
|
||||
return {
|
||||
file: void 0,
|
||||
start: void 0,
|
||||
length: void 0,
|
||||
category: ts4.DiagnosticCategory.Message,
|
||||
messageText,
|
||||
code: DEFAULT_ERROR_CODE,
|
||||
source: SOURCE
|
||||
};
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/perform_compile.js
|
||||
var defaultFormatHost = {
|
||||
getCurrentDirectory: () => ts5.sys.getCurrentDirectory(),
|
||||
getCanonicalFileName: (fileName) => fileName,
|
||||
getNewLine: () => ts5.sys.newLine
|
||||
};
|
||||
function formatDiagnostics(diags, host = defaultFormatHost) {
|
||||
if (diags && diags.length) {
|
||||
return diags.map((diagnostic) => replaceTsWithNgInErrors(ts5.formatDiagnosticsWithColorAndContext([diagnostic], host))).join("");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
function calcProjectFileAndBasePath(project, host = getFileSystem()) {
|
||||
const absProject = host.resolve(project);
|
||||
const projectIsDir = host.lstat(absProject).isDirectory();
|
||||
const projectFile = projectIsDir ? host.join(absProject, "tsconfig.json") : absProject;
|
||||
const projectDir = projectIsDir ? absProject : host.dirname(absProject);
|
||||
const basePath = host.resolve(projectDir);
|
||||
return { projectFile, basePath };
|
||||
}
|
||||
function readConfiguration(project, existingOptions, host = getFileSystem()) {
|
||||
try {
|
||||
const fs = getFileSystem();
|
||||
const readConfigFile = (configFile) => ts5.readConfigFile(configFile, (file) => host.readFile(host.resolve(file)));
|
||||
const readAngularCompilerOptions = (configFile, parentOptions = {}) => {
|
||||
const { config: config2, error: error2 } = readConfigFile(configFile);
|
||||
if (error2) {
|
||||
return parentOptions;
|
||||
}
|
||||
const angularCompilerOptions = config2.angularCompilerOptions ?? config2.bazelOptions?.angularCompilerOptions;
|
||||
let existingNgCompilerOptions = { ...angularCompilerOptions, ...parentOptions };
|
||||
if (!config2.extends) {
|
||||
return existingNgCompilerOptions;
|
||||
}
|
||||
const extendsPaths = typeof config2.extends === "string" ? [config2.extends] : config2.extends;
|
||||
return [...extendsPaths].reverse().reduce((prevOptions, extendsPath) => {
|
||||
const extendedConfigPath = getExtendedConfigPath(configFile, extendsPath, host, fs);
|
||||
return extendedConfigPath === null ? prevOptions : readAngularCompilerOptions(extendedConfigPath, prevOptions);
|
||||
}, existingNgCompilerOptions);
|
||||
};
|
||||
const { projectFile, basePath } = calcProjectFileAndBasePath(project, host);
|
||||
const configFileName = host.resolve(host.pwd(), projectFile);
|
||||
const { config, error } = readConfigFile(projectFile);
|
||||
if (error) {
|
||||
return {
|
||||
project,
|
||||
errors: [error],
|
||||
rootNames: [],
|
||||
options: {},
|
||||
emitFlags: EmitFlags.Default
|
||||
};
|
||||
}
|
||||
const existingCompilerOptions = {
|
||||
genDir: basePath,
|
||||
basePath,
|
||||
...readAngularCompilerOptions(configFileName),
|
||||
...existingOptions
|
||||
};
|
||||
const parseConfigHost = createParseConfigHost(host, fs);
|
||||
const { options, errors, fileNames: rootNames, projectReferences } = ts5.parseJsonConfigFileContent(config, parseConfigHost, basePath, existingCompilerOptions, configFileName);
|
||||
let emitFlags = EmitFlags.Default;
|
||||
if (!(options["skipMetadataEmit"] || options["flatModuleOutFile"])) {
|
||||
emitFlags |= EmitFlags.Metadata;
|
||||
}
|
||||
if (options["skipTemplateCodegen"]) {
|
||||
emitFlags = emitFlags & ~EmitFlags.Codegen;
|
||||
}
|
||||
return { project: projectFile, rootNames, projectReferences, options, errors, emitFlags };
|
||||
} catch (e) {
|
||||
const errors = [
|
||||
{
|
||||
category: ts5.DiagnosticCategory.Error,
|
||||
messageText: e.stack ?? e.message,
|
||||
file: void 0,
|
||||
start: void 0,
|
||||
length: void 0,
|
||||
source: "angular",
|
||||
code: UNKNOWN_ERROR_CODE
|
||||
}
|
||||
];
|
||||
return { project: "", errors, rootNames: [], options: {}, emitFlags: EmitFlags.Default };
|
||||
}
|
||||
}
|
||||
function createParseConfigHost(host, fs = getFileSystem()) {
|
||||
return {
|
||||
fileExists: host.exists.bind(host),
|
||||
readDirectory: createFileSystemTsReadDirectoryFn(fs),
|
||||
readFile: host.readFile.bind(host),
|
||||
useCaseSensitiveFileNames: fs.isCaseSensitive()
|
||||
};
|
||||
}
|
||||
function getExtendedConfigPath(configFile, extendsValue, host, fs) {
|
||||
const result = getExtendedConfigPathWorker(configFile, extendsValue, host, fs);
|
||||
if (result !== null) {
|
||||
return result;
|
||||
}
|
||||
return getExtendedConfigPathWorker(configFile, `${extendsValue}.json`, host, fs);
|
||||
}
|
||||
function getExtendedConfigPathWorker(configFile, extendsValue, host, fs) {
|
||||
if (extendsValue.startsWith(".") || fs.isRooted(extendsValue)) {
|
||||
const extendedConfigPath = host.resolve(host.dirname(configFile), extendsValue);
|
||||
if (host.exists(extendedConfigPath)) {
|
||||
return extendedConfigPath;
|
||||
}
|
||||
} else {
|
||||
const parseConfigHost = createParseConfigHost(host, fs);
|
||||
const { resolvedModule } = ts5.nodeModuleNameResolver(extendsValue, configFile, { moduleResolution: ts5.ModuleResolutionKind.NodeNext, resolveJsonModule: true }, parseConfigHost);
|
||||
if (resolvedModule) {
|
||||
return absoluteFrom(resolvedModule.resolvedFileName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function exitCodeFromResult(diags) {
|
||||
if (!diags)
|
||||
return 0;
|
||||
if (diags.every((diag) => diag.category !== ts5.DiagnosticCategory.Error)) {
|
||||
return 0;
|
||||
}
|
||||
return diags.some((d) => d.source === "angular" && d.code === UNKNOWN_ERROR_CODE) ? 2 : 1;
|
||||
}
|
||||
function performCompilation({ rootNames, options, host, oldProgram, emitCallback, mergeEmitResultsCallback, gatherDiagnostics = defaultGatherDiagnostics, customTransformers, emitFlags = EmitFlags.Default, forceEmit = false, modifiedResourceFiles = null }) {
|
||||
let program;
|
||||
let emitResult;
|
||||
let allDiagnostics = [];
|
||||
try {
|
||||
if (!host) {
|
||||
host = createCompilerHost({ options });
|
||||
}
|
||||
if (modifiedResourceFiles) {
|
||||
host.getModifiedResourceFiles = () => modifiedResourceFiles;
|
||||
}
|
||||
program = createProgram({ rootNames, host, options, oldProgram });
|
||||
const beforeDiags = Date.now();
|
||||
allDiagnostics.push(...gatherDiagnostics(program));
|
||||
if (options.diagnostics) {
|
||||
const afterDiags = Date.now();
|
||||
allDiagnostics.push(createMessageDiagnostic(`Time for diagnostics: ${afterDiags - beforeDiags}ms.`));
|
||||
}
|
||||
if (!hasErrors(allDiagnostics)) {
|
||||
emitResult = program.emit({
|
||||
emitCallback,
|
||||
mergeEmitResultsCallback,
|
||||
customTransformers,
|
||||
emitFlags,
|
||||
forceEmit
|
||||
});
|
||||
allDiagnostics.push(...emitResult.diagnostics);
|
||||
return { diagnostics: allDiagnostics, program, emitResult };
|
||||
}
|
||||
return { diagnostics: allDiagnostics, program };
|
||||
} catch (e) {
|
||||
program = void 0;
|
||||
allDiagnostics.push({
|
||||
category: ts5.DiagnosticCategory.Error,
|
||||
messageText: e.stack ?? e.message,
|
||||
code: UNKNOWN_ERROR_CODE,
|
||||
file: void 0,
|
||||
start: void 0,
|
||||
length: void 0
|
||||
});
|
||||
return { diagnostics: allDiagnostics, program };
|
||||
}
|
||||
}
|
||||
function defaultGatherDiagnostics(program) {
|
||||
const allDiagnostics = [];
|
||||
function checkDiagnostics(diags) {
|
||||
if (diags) {
|
||||
allDiagnostics.push(...diags);
|
||||
return !hasErrors(diags);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
let checkOtherDiagnostics = true;
|
||||
checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics([...program.getTsOptionDiagnostics(), ...program.getNgOptionDiagnostics()]);
|
||||
checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics(program.getTsSyntacticDiagnostics());
|
||||
checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics([
|
||||
...program.getTsSemanticDiagnostics(),
|
||||
...program.getNgStructuralDiagnostics()
|
||||
]);
|
||||
checkOtherDiagnostics = checkOtherDiagnostics && checkDiagnostics(program.getNgSemanticDiagnostics());
|
||||
return allDiagnostics;
|
||||
}
|
||||
function hasErrors(diags) {
|
||||
return diags.some((d) => d.category === ts5.DiagnosticCategory.Error);
|
||||
}
|
||||
|
||||
export {
|
||||
DEFAULT_ERROR_CODE,
|
||||
UNKNOWN_ERROR_CODE,
|
||||
SOURCE,
|
||||
isTsDiagnostic,
|
||||
EmitFlags,
|
||||
createCompilerHost,
|
||||
NgtscProgram,
|
||||
createProgram,
|
||||
createMessageDiagnostic,
|
||||
formatDiagnostics,
|
||||
calcProjectFileAndBasePath,
|
||||
readConfiguration,
|
||||
exitCodeFromResult,
|
||||
performCompilation,
|
||||
defaultGatherDiagnostics
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+378
@@ -0,0 +1,378 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
DEFAULT_ERROR_CODE,
|
||||
EmitFlags,
|
||||
SOURCE,
|
||||
createCompilerHost,
|
||||
createMessageDiagnostic,
|
||||
exitCodeFromResult,
|
||||
formatDiagnostics,
|
||||
performCompilation,
|
||||
readConfiguration
|
||||
} from "./chunk-VO3Q626H.js";
|
||||
|
||||
// packages/compiler-cli/src/main.js
|
||||
import ts2 from "typescript";
|
||||
import yargs from "yargs";
|
||||
|
||||
// packages/compiler-cli/src/perform_watch.js
|
||||
import * as chokidar from "chokidar";
|
||||
import * as path from "path";
|
||||
import ts from "typescript";
|
||||
function totalCompilationTimeDiagnostic(timeInMillis) {
|
||||
let duration;
|
||||
if (timeInMillis > 1e3) {
|
||||
duration = `${(timeInMillis / 1e3).toPrecision(2)}s`;
|
||||
} else {
|
||||
duration = `${timeInMillis}ms`;
|
||||
}
|
||||
return {
|
||||
category: ts.DiagnosticCategory.Message,
|
||||
messageText: `Total time: ${duration}`,
|
||||
code: DEFAULT_ERROR_CODE,
|
||||
source: SOURCE,
|
||||
file: void 0,
|
||||
start: void 0,
|
||||
length: void 0
|
||||
};
|
||||
}
|
||||
var FileChangeEvent;
|
||||
(function(FileChangeEvent2) {
|
||||
FileChangeEvent2[FileChangeEvent2["Change"] = 0] = "Change";
|
||||
FileChangeEvent2[FileChangeEvent2["CreateDelete"] = 1] = "CreateDelete";
|
||||
FileChangeEvent2[FileChangeEvent2["CreateDeleteDir"] = 2] = "CreateDeleteDir";
|
||||
})(FileChangeEvent || (FileChangeEvent = {}));
|
||||
function createPerformWatchHost(configFileName, reportDiagnostics, existingOptions, createEmitCallback) {
|
||||
return {
|
||||
reportDiagnostics,
|
||||
createCompilerHost: (options) => createCompilerHost({ options }),
|
||||
readConfiguration: () => readConfiguration(configFileName, existingOptions),
|
||||
createEmitCallback: (options) => createEmitCallback ? createEmitCallback(options) : void 0,
|
||||
onFileChange: (options, listener, ready) => {
|
||||
if (!options.basePath) {
|
||||
reportDiagnostics([
|
||||
{
|
||||
category: ts.DiagnosticCategory.Error,
|
||||
messageText: "Invalid configuration option. baseDir not specified",
|
||||
source: SOURCE,
|
||||
code: DEFAULT_ERROR_CODE,
|
||||
file: void 0,
|
||||
start: void 0,
|
||||
length: void 0
|
||||
}
|
||||
]);
|
||||
return { close: () => {
|
||||
} };
|
||||
}
|
||||
const watcher = chokidar.watch(options.basePath, {
|
||||
// ignore .dotfiles, .js and .map files.
|
||||
// can't ignore other files as we e.g. want to recompile if an `.html` file changes as well.
|
||||
ignored: (path2) => /((^[\/\\])\..)|(\.js$)|(\.map$)|(\.metadata\.json|node_modules)/.test(path2),
|
||||
ignoreInitial: true,
|
||||
persistent: true
|
||||
});
|
||||
watcher.on("all", (event, path2) => {
|
||||
switch (event) {
|
||||
case "change":
|
||||
listener(FileChangeEvent.Change, path2);
|
||||
break;
|
||||
case "unlink":
|
||||
case "add":
|
||||
listener(FileChangeEvent.CreateDelete, path2);
|
||||
break;
|
||||
case "unlinkDir":
|
||||
case "addDir":
|
||||
listener(FileChangeEvent.CreateDeleteDir, path2);
|
||||
break;
|
||||
}
|
||||
});
|
||||
watcher.on("ready", ready);
|
||||
return { close: () => watcher.close(), ready };
|
||||
},
|
||||
setTimeout: ts.sys.clearTimeout && ts.sys.setTimeout || setTimeout,
|
||||
clearTimeout: ts.sys.setTimeout && ts.sys.clearTimeout || clearTimeout
|
||||
};
|
||||
}
|
||||
function performWatchCompilation(host) {
|
||||
let cachedProgram;
|
||||
let cachedCompilerHost;
|
||||
let cachedOptions;
|
||||
let timerHandleForRecompilation;
|
||||
const ignoreFilesForWatch = /* @__PURE__ */ new Set();
|
||||
const fileCache = /* @__PURE__ */ new Map();
|
||||
const firstCompileResult = doCompilation();
|
||||
let resolveReadyPromise;
|
||||
const readyPromise = new Promise((resolve) => resolveReadyPromise = resolve);
|
||||
const fileWatcher = host.onFileChange(cachedOptions.options, watchedFileChanged, resolveReadyPromise);
|
||||
return { close, ready: (cb) => readyPromise.then(cb), firstCompileResult };
|
||||
function cacheEntry(fileName) {
|
||||
fileName = path.normalize(fileName);
|
||||
let entry = fileCache.get(fileName);
|
||||
if (!entry) {
|
||||
entry = {};
|
||||
fileCache.set(fileName, entry);
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
function close() {
|
||||
fileWatcher.close();
|
||||
if (timerHandleForRecompilation) {
|
||||
host.clearTimeout(timerHandleForRecompilation.timerHandle);
|
||||
timerHandleForRecompilation = void 0;
|
||||
}
|
||||
}
|
||||
function doCompilation() {
|
||||
if (!cachedOptions) {
|
||||
cachedOptions = host.readConfiguration();
|
||||
}
|
||||
if (cachedOptions.errors && cachedOptions.errors.length) {
|
||||
host.reportDiagnostics(cachedOptions.errors);
|
||||
return cachedOptions.errors;
|
||||
}
|
||||
const startTime = Date.now();
|
||||
if (!cachedCompilerHost) {
|
||||
cachedCompilerHost = host.createCompilerHost(cachedOptions.options);
|
||||
const originalWriteFileCallback = cachedCompilerHost.writeFile;
|
||||
cachedCompilerHost.writeFile = function(fileName, data, writeByteOrderMark, onError, sourceFiles = []) {
|
||||
ignoreFilesForWatch.add(path.normalize(fileName));
|
||||
return originalWriteFileCallback(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
||||
};
|
||||
const originalFileExists = cachedCompilerHost.fileExists;
|
||||
cachedCompilerHost.fileExists = function(fileName) {
|
||||
const ce = cacheEntry(fileName);
|
||||
if (ce.exists == null) {
|
||||
ce.exists = originalFileExists.call(this, fileName);
|
||||
}
|
||||
return ce.exists;
|
||||
};
|
||||
const originalGetSourceFile = cachedCompilerHost.getSourceFile;
|
||||
cachedCompilerHost.getSourceFile = function(fileName, languageVersion) {
|
||||
const ce = cacheEntry(fileName);
|
||||
if (!ce.sf) {
|
||||
ce.sf = originalGetSourceFile.call(this, fileName, languageVersion);
|
||||
}
|
||||
return ce.sf;
|
||||
};
|
||||
const originalReadFile = cachedCompilerHost.readFile;
|
||||
cachedCompilerHost.readFile = function(fileName) {
|
||||
const ce = cacheEntry(fileName);
|
||||
if (ce.content == null) {
|
||||
ce.content = originalReadFile.call(this, fileName);
|
||||
}
|
||||
return ce.content;
|
||||
};
|
||||
cachedCompilerHost.getModifiedResourceFiles = function() {
|
||||
if (timerHandleForRecompilation === void 0) {
|
||||
return void 0;
|
||||
}
|
||||
return timerHandleForRecompilation.modifiedResourceFiles;
|
||||
};
|
||||
}
|
||||
ignoreFilesForWatch.clear();
|
||||
const oldProgram = cachedProgram;
|
||||
cachedProgram = void 0;
|
||||
const compileResult = performCompilation({
|
||||
rootNames: cachedOptions.rootNames,
|
||||
options: cachedOptions.options,
|
||||
host: cachedCompilerHost,
|
||||
oldProgram,
|
||||
emitCallback: host.createEmitCallback(cachedOptions.options)
|
||||
});
|
||||
if (compileResult.diagnostics.length) {
|
||||
host.reportDiagnostics(compileResult.diagnostics);
|
||||
}
|
||||
const endTime = Date.now();
|
||||
if (cachedOptions.options.diagnostics) {
|
||||
const totalTime = (endTime - startTime) / 1e3;
|
||||
host.reportDiagnostics([totalCompilationTimeDiagnostic(endTime - startTime)]);
|
||||
}
|
||||
const exitCode = exitCodeFromResult(compileResult.diagnostics);
|
||||
if (exitCode == 0) {
|
||||
cachedProgram = compileResult.program;
|
||||
host.reportDiagnostics([
|
||||
createMessageDiagnostic("Compilation complete. Watching for file changes.")
|
||||
]);
|
||||
} else {
|
||||
host.reportDiagnostics([
|
||||
createMessageDiagnostic("Compilation failed. Watching for file changes.")
|
||||
]);
|
||||
}
|
||||
return compileResult.diagnostics;
|
||||
}
|
||||
function resetOptions() {
|
||||
cachedProgram = void 0;
|
||||
cachedCompilerHost = void 0;
|
||||
cachedOptions = void 0;
|
||||
}
|
||||
function watchedFileChanged(event, fileName) {
|
||||
const normalizedPath = path.normalize(fileName);
|
||||
if (cachedOptions && event === FileChangeEvent.Change && // TODO(chuckj): validate that this is sufficient to skip files that were written.
|
||||
// This assumes that the file path we write is the same file path we will receive in the
|
||||
// change notification.
|
||||
normalizedPath === path.normalize(cachedOptions.project)) {
|
||||
resetOptions();
|
||||
} else if (event === FileChangeEvent.CreateDelete || event === FileChangeEvent.CreateDeleteDir) {
|
||||
cachedOptions = void 0;
|
||||
}
|
||||
if (event === FileChangeEvent.CreateDeleteDir) {
|
||||
fileCache.clear();
|
||||
} else {
|
||||
fileCache.delete(normalizedPath);
|
||||
}
|
||||
if (!ignoreFilesForWatch.has(normalizedPath)) {
|
||||
startTimerForRecompilation(normalizedPath);
|
||||
}
|
||||
}
|
||||
function startTimerForRecompilation(changedPath) {
|
||||
if (timerHandleForRecompilation) {
|
||||
host.clearTimeout(timerHandleForRecompilation.timerHandle);
|
||||
} else {
|
||||
timerHandleForRecompilation = {
|
||||
modifiedResourceFiles: /* @__PURE__ */ new Set(),
|
||||
timerHandle: void 0
|
||||
};
|
||||
}
|
||||
timerHandleForRecompilation.timerHandle = host.setTimeout(recompile, 250);
|
||||
timerHandleForRecompilation.modifiedResourceFiles.add(changedPath);
|
||||
}
|
||||
function recompile() {
|
||||
host.reportDiagnostics([
|
||||
createMessageDiagnostic("File change detected. Starting incremental compilation.")
|
||||
]);
|
||||
doCompilation();
|
||||
timerHandleForRecompilation = void 0;
|
||||
}
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/main.js
|
||||
function main(args, consoleError = console.error, config, customTransformers, programReuse, modifiedResourceFiles) {
|
||||
let { project, rootNames, options, errors: configErrors, watch: watch2, emitFlags } = config || readNgcCommandLineAndConfiguration(args);
|
||||
if (configErrors.length) {
|
||||
return reportErrorsAndExit(
|
||||
configErrors,
|
||||
/*options*/
|
||||
void 0,
|
||||
consoleError
|
||||
);
|
||||
}
|
||||
if (watch2) {
|
||||
const result = watchMode(project, options, consoleError);
|
||||
return reportErrorsAndExit(result.firstCompileResult, options, consoleError);
|
||||
}
|
||||
let oldProgram;
|
||||
if (programReuse !== void 0) {
|
||||
oldProgram = programReuse.program;
|
||||
}
|
||||
const { diagnostics: compileDiags, program } = performCompilation({
|
||||
rootNames,
|
||||
options,
|
||||
emitFlags,
|
||||
oldProgram,
|
||||
customTransformers,
|
||||
modifiedResourceFiles
|
||||
});
|
||||
if (programReuse !== void 0) {
|
||||
programReuse.program = program;
|
||||
}
|
||||
return reportErrorsAndExit(compileDiags, options, consoleError);
|
||||
}
|
||||
function readNgcCommandLineAndConfiguration(args) {
|
||||
const options = {};
|
||||
const parsedArgs = yargs(args).parserConfiguration({ "strip-aliased": true }).option("i18nFile", { type: "string" }).option("i18nFormat", { type: "string" }).option("locale", { type: "string" }).option("missingTranslation", { type: "string", choices: ["error", "warning", "ignore"] }).option("outFile", { type: "string" }).option("watch", { type: "boolean", alias: ["w"] }).parseSync();
|
||||
if (parsedArgs.i18nFile)
|
||||
options.i18nInFile = parsedArgs.i18nFile;
|
||||
if (parsedArgs.i18nFormat)
|
||||
options.i18nInFormat = parsedArgs.i18nFormat;
|
||||
if (parsedArgs.locale)
|
||||
options.i18nInLocale = parsedArgs.locale;
|
||||
if (parsedArgs.missingTranslation)
|
||||
options.i18nInMissingTranslations = parsedArgs.missingTranslation;
|
||||
const config = readCommandLineAndConfiguration(args, options, [
|
||||
"i18nFile",
|
||||
"i18nFormat",
|
||||
"locale",
|
||||
"missingTranslation",
|
||||
"watch"
|
||||
]);
|
||||
return { ...config, watch: parsedArgs.watch };
|
||||
}
|
||||
function readCommandLineAndConfiguration(args, existingOptions = {}, ngCmdLineOptions = []) {
|
||||
let cmdConfig = ts2.parseCommandLine(args);
|
||||
const project = cmdConfig.options.project || ".";
|
||||
const cmdErrors = cmdConfig.errors.filter((e) => {
|
||||
if (typeof e.messageText === "string") {
|
||||
const msg = e.messageText;
|
||||
return !ngCmdLineOptions.some((o) => msg.indexOf(o) >= 0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (cmdErrors.length) {
|
||||
return {
|
||||
project,
|
||||
rootNames: [],
|
||||
options: cmdConfig.options,
|
||||
errors: cmdErrors,
|
||||
emitFlags: EmitFlags.Default
|
||||
};
|
||||
}
|
||||
const config = readConfiguration(project, cmdConfig.options);
|
||||
const options = { ...config.options, ...existingOptions };
|
||||
if (options.locale) {
|
||||
options.i18nInLocale = options.locale;
|
||||
}
|
||||
return {
|
||||
project,
|
||||
rootNames: config.rootNames,
|
||||
options,
|
||||
errors: config.errors,
|
||||
emitFlags: config.emitFlags
|
||||
};
|
||||
}
|
||||
function getFormatDiagnosticsHost(options) {
|
||||
const basePath = options ? options.basePath : void 0;
|
||||
return {
|
||||
getCurrentDirectory: () => basePath || ts2.sys.getCurrentDirectory(),
|
||||
// We need to normalize the path separators here because by default, TypeScript
|
||||
// compiler hosts use posix canonical paths. In order to print consistent diagnostics,
|
||||
// we also normalize the paths.
|
||||
getCanonicalFileName: (fileName) => fileName.replace(/\\/g, "/"),
|
||||
getNewLine: () => {
|
||||
if (options && options.newLine !== void 0) {
|
||||
return options.newLine === ts2.NewLineKind.LineFeed ? "\n" : "\r\n";
|
||||
}
|
||||
return ts2.sys.newLine;
|
||||
}
|
||||
};
|
||||
}
|
||||
function reportErrorsAndExit(allDiagnostics, options, consoleError = console.error) {
|
||||
const errorsAndWarnings = allDiagnostics.filter((d) => d.category !== ts2.DiagnosticCategory.Message);
|
||||
printDiagnostics(errorsAndWarnings, options, consoleError);
|
||||
return exitCodeFromResult(allDiagnostics);
|
||||
}
|
||||
function watchMode(project, options, consoleError) {
|
||||
return performWatchCompilation(createPerformWatchHost(project, (diagnostics) => {
|
||||
printDiagnostics(diagnostics, options, consoleError);
|
||||
}, options, void 0));
|
||||
}
|
||||
function printDiagnostics(diagnostics, options, consoleError) {
|
||||
if (diagnostics.length === 0) {
|
||||
return;
|
||||
}
|
||||
const formatHost = getFormatDiagnosticsHost(options);
|
||||
consoleError(formatDiagnostics(diagnostics, formatHost));
|
||||
}
|
||||
|
||||
export {
|
||||
main,
|
||||
readCommandLineAndConfiguration
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
__require
|
||||
} from "./chunk-G7GFT6BU.js";
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.js
|
||||
import fs from "fs";
|
||||
import { createRequire } from "module";
|
||||
import * as p from "path";
|
||||
import * as url from "url";
|
||||
var NodeJSPathManipulation = class {
|
||||
pwd() {
|
||||
return this.normalize(process.cwd());
|
||||
}
|
||||
chdir(dir) {
|
||||
process.chdir(dir);
|
||||
}
|
||||
resolve(...paths) {
|
||||
return this.normalize(p.resolve(...paths));
|
||||
}
|
||||
dirname(file) {
|
||||
return this.normalize(p.dirname(file));
|
||||
}
|
||||
join(basePath, ...paths) {
|
||||
return this.normalize(p.join(basePath, ...paths));
|
||||
}
|
||||
isRoot(path) {
|
||||
return this.dirname(path) === this.normalize(path);
|
||||
}
|
||||
isRooted(path) {
|
||||
return p.isAbsolute(path);
|
||||
}
|
||||
relative(from, to) {
|
||||
return this.normalize(p.relative(from, to));
|
||||
}
|
||||
basename(filePath, extension) {
|
||||
return p.basename(filePath, extension);
|
||||
}
|
||||
extname(path) {
|
||||
return p.extname(path);
|
||||
}
|
||||
normalize(path) {
|
||||
return path.replace(/\\/g, "/");
|
||||
}
|
||||
};
|
||||
var isCommonJS = typeof __filename !== "undefined";
|
||||
var currentFileUrl = isCommonJS ? null : import.meta.url;
|
||||
var currentFileName = isCommonJS ? __filename : url.fileURLToPath?.(currentFileUrl) ?? null;
|
||||
var NodeJSReadonlyFileSystem = class extends NodeJSPathManipulation {
|
||||
_caseSensitive = void 0;
|
||||
isCaseSensitive() {
|
||||
if (this._caseSensitive === void 0) {
|
||||
this._caseSensitive = currentFileName !== null ? !fs.existsSync(this.normalize(toggleCase(currentFileName))) : true;
|
||||
}
|
||||
return this._caseSensitive;
|
||||
}
|
||||
exists(path) {
|
||||
return fs.existsSync(path);
|
||||
}
|
||||
readFile(path) {
|
||||
return fs.readFileSync(path, "utf8");
|
||||
}
|
||||
readFileBuffer(path) {
|
||||
return fs.readFileSync(path);
|
||||
}
|
||||
readdir(path) {
|
||||
return fs.readdirSync(path);
|
||||
}
|
||||
lstat(path) {
|
||||
return fs.lstatSync(path);
|
||||
}
|
||||
stat(path) {
|
||||
return fs.statSync(path);
|
||||
}
|
||||
realpath(path) {
|
||||
return this.resolve(fs.realpathSync(path));
|
||||
}
|
||||
getDefaultLibLocation() {
|
||||
const requireFn = isCommonJS ? __require : createRequire(currentFileUrl);
|
||||
return this.resolve(requireFn.resolve("typescript"), "..");
|
||||
}
|
||||
};
|
||||
var NodeJSFileSystem = class extends NodeJSReadonlyFileSystem {
|
||||
writeFile(path, data, exclusive = false) {
|
||||
fs.writeFileSync(path, data, exclusive ? { flag: "wx" } : void 0);
|
||||
}
|
||||
removeFile(path) {
|
||||
fs.unlinkSync(path);
|
||||
}
|
||||
symlink(target, path) {
|
||||
fs.symlinkSync(target, path);
|
||||
}
|
||||
copyFile(from, to) {
|
||||
fs.copyFileSync(from, to);
|
||||
}
|
||||
moveFile(from, to) {
|
||||
fs.renameSync(from, to);
|
||||
}
|
||||
ensureDir(path) {
|
||||
fs.mkdirSync(path, { recursive: true });
|
||||
}
|
||||
removeDeep(path) {
|
||||
fs.rmdirSync(path, { recursive: true });
|
||||
}
|
||||
};
|
||||
function toggleCase(str) {
|
||||
return str.replace(/\w/g, (ch) => ch.toUpperCase() === ch ? ch.toLowerCase() : ch.toUpperCase());
|
||||
}
|
||||
|
||||
export {
|
||||
NodeJSFileSystem
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
DEFAULT_ERROR_CODE,
|
||||
EmitFlags,
|
||||
NgtscProgram,
|
||||
SOURCE,
|
||||
UNKNOWN_ERROR_CODE,
|
||||
calcProjectFileAndBasePath,
|
||||
createCompilerHost,
|
||||
createProgram,
|
||||
defaultGatherDiagnostics,
|
||||
exitCodeFromResult,
|
||||
formatDiagnostics,
|
||||
isTsDiagnostic,
|
||||
performCompilation,
|
||||
readConfiguration
|
||||
} from "./chunk-VO3Q626H.js";
|
||||
import {
|
||||
ConsoleLogger,
|
||||
LogLevel
|
||||
} from "./chunk-6HOSNZU5.js";
|
||||
import {
|
||||
DecoratorType,
|
||||
DocsExtractor,
|
||||
EntryType,
|
||||
MemberTags,
|
||||
MemberType,
|
||||
NgCompiler,
|
||||
NgCompilerHost,
|
||||
PatchedProgramIncrementalBuildStrategy,
|
||||
freshCompilationTicket,
|
||||
incrementalFromStateTicket,
|
||||
isDocEntryWithSourceInfo
|
||||
} from "./chunk-PW54LIP6.js";
|
||||
import {
|
||||
ActivePerfRecorder,
|
||||
ErrorCode,
|
||||
OptimizeFor,
|
||||
PerfPhase,
|
||||
TsCreateProgramDriver,
|
||||
angularJitApplicationTransform,
|
||||
getDownlevelDecoratorsTransform,
|
||||
getInitializerApiJitTransform,
|
||||
isLocalCompilationDiagnostics,
|
||||
ngErrorCode
|
||||
} from "./chunk-IG22BDVK.js";
|
||||
import "./chunk-CSUVPNMK.js";
|
||||
import {
|
||||
InvalidFileSystem,
|
||||
LogicalFileSystem,
|
||||
LogicalProjectPath,
|
||||
NgtscCompilerHost,
|
||||
absoluteFrom,
|
||||
absoluteFromSourceFile,
|
||||
basename,
|
||||
createFileSystemTsReadDirectoryFn,
|
||||
dirname,
|
||||
getFileSystem,
|
||||
getSourceFileOrError,
|
||||
isLocalRelativePath,
|
||||
isRoot,
|
||||
isRooted,
|
||||
join,
|
||||
relative,
|
||||
relativeFrom,
|
||||
resolve,
|
||||
setFileSystem,
|
||||
toRelativeImport
|
||||
} from "./chunk-CEBE44Q5.js";
|
||||
import {
|
||||
NodeJSFileSystem
|
||||
} from "./chunk-XYYEESKY.js";
|
||||
import "./chunk-G7GFT6BU.js";
|
||||
|
||||
// packages/compiler-cli/src/version.js
|
||||
import { Version } from "@angular/compiler";
|
||||
var VERSION = new Version("21.2.1");
|
||||
|
||||
// packages/compiler-cli/private/tooling.js
|
||||
var GLOBAL_DEFS_FOR_TERSER = {
|
||||
ngDevMode: false,
|
||||
ngI18nClosureMode: false
|
||||
};
|
||||
var GLOBAL_DEFS_FOR_TERSER_WITH_AOT = {
|
||||
...GLOBAL_DEFS_FOR_TERSER,
|
||||
ngJitMode: false
|
||||
};
|
||||
var constructorParametersDownlevelTransform = (program, isCore = false) => {
|
||||
return angularJitApplicationTransform(program, isCore);
|
||||
};
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/tsc_plugin.js
|
||||
var NgTscPlugin = class {
|
||||
ngOptions;
|
||||
name = "ngtsc";
|
||||
options = null;
|
||||
host = null;
|
||||
_compiler = null;
|
||||
get compiler() {
|
||||
if (this._compiler === null) {
|
||||
throw new Error("Lifecycle error: setupCompilation() must be called first.");
|
||||
}
|
||||
return this._compiler;
|
||||
}
|
||||
constructor(ngOptions) {
|
||||
this.ngOptions = ngOptions;
|
||||
setFileSystem(new NodeJSFileSystem());
|
||||
}
|
||||
wrapHost(host, inputFiles, options) {
|
||||
this.options = { ...this.ngOptions, ...options };
|
||||
this.host = NgCompilerHost.wrap(
|
||||
host,
|
||||
inputFiles,
|
||||
this.options,
|
||||
/* oldProgram */
|
||||
null
|
||||
);
|
||||
return this.host;
|
||||
}
|
||||
setupCompilation(program, oldProgram) {
|
||||
const perfRecorder = ActivePerfRecorder.zeroedToNow();
|
||||
if (this.host === null || this.options === null) {
|
||||
throw new Error("Lifecycle error: setupCompilation() before wrapHost().");
|
||||
}
|
||||
this.host.postProgramCreationCleanup();
|
||||
const programDriver = new TsCreateProgramDriver(program, this.host, this.options, this.host.shimExtensionPrefixes);
|
||||
const strategy = new PatchedProgramIncrementalBuildStrategy();
|
||||
const oldState = oldProgram !== void 0 ? strategy.getIncrementalState(oldProgram) : null;
|
||||
let ticket;
|
||||
const modifiedResourceFiles = /* @__PURE__ */ new Set();
|
||||
if (this.host.getModifiedResourceFiles !== void 0) {
|
||||
for (const resourceFile of this.host.getModifiedResourceFiles() ?? []) {
|
||||
modifiedResourceFiles.add(resolve(resourceFile));
|
||||
}
|
||||
}
|
||||
if (oldProgram === void 0 || oldState === null) {
|
||||
ticket = freshCompilationTicket(
|
||||
program,
|
||||
this.options,
|
||||
strategy,
|
||||
programDriver,
|
||||
perfRecorder,
|
||||
/* enableTemplateTypeChecker */
|
||||
false,
|
||||
/* usePoisonedData */
|
||||
false
|
||||
);
|
||||
} else {
|
||||
strategy.toNextBuildStrategy().getIncrementalState(oldProgram);
|
||||
ticket = incrementalFromStateTicket(oldProgram, oldState, program, this.options, strategy, programDriver, modifiedResourceFiles, perfRecorder, false, false);
|
||||
}
|
||||
this._compiler = NgCompiler.fromTicket(ticket, this.host);
|
||||
return {
|
||||
ignoreForDiagnostics: this._compiler.ignoreForDiagnostics,
|
||||
ignoreForEmit: this._compiler.ignoreForEmit
|
||||
};
|
||||
}
|
||||
getDiagnostics(file) {
|
||||
if (file === void 0) {
|
||||
return this.compiler.getDiagnostics();
|
||||
}
|
||||
return this.compiler.getDiagnosticsForFile(file, OptimizeFor.WholeProgram);
|
||||
}
|
||||
getOptionDiagnostics() {
|
||||
return this.compiler.getOptionDiagnostics();
|
||||
}
|
||||
getNextProgram() {
|
||||
return this.compiler.getCurrentProgram();
|
||||
}
|
||||
createTransformers() {
|
||||
this.compiler.perfRecorder.phase(PerfPhase.TypeScriptEmit);
|
||||
return this.compiler.prepareEmit().transformers;
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/index.ts
|
||||
setFileSystem(new NodeJSFileSystem());
|
||||
export {
|
||||
ConsoleLogger,
|
||||
DEFAULT_ERROR_CODE,
|
||||
DecoratorType,
|
||||
DocsExtractor,
|
||||
EmitFlags,
|
||||
EntryType,
|
||||
ErrorCode,
|
||||
GLOBAL_DEFS_FOR_TERSER,
|
||||
GLOBAL_DEFS_FOR_TERSER_WITH_AOT,
|
||||
InvalidFileSystem,
|
||||
LogLevel,
|
||||
LogicalFileSystem,
|
||||
LogicalProjectPath,
|
||||
MemberTags,
|
||||
MemberType,
|
||||
NgTscPlugin,
|
||||
NgtscCompilerHost,
|
||||
NgtscProgram,
|
||||
NodeJSFileSystem,
|
||||
OptimizeFor,
|
||||
SOURCE,
|
||||
UNKNOWN_ERROR_CODE,
|
||||
VERSION,
|
||||
absoluteFrom,
|
||||
absoluteFromSourceFile,
|
||||
angularJitApplicationTransform,
|
||||
basename,
|
||||
calcProjectFileAndBasePath,
|
||||
constructorParametersDownlevelTransform,
|
||||
createCompilerHost,
|
||||
createFileSystemTsReadDirectoryFn,
|
||||
createProgram,
|
||||
defaultGatherDiagnostics,
|
||||
dirname,
|
||||
exitCodeFromResult,
|
||||
formatDiagnostics,
|
||||
getDownlevelDecoratorsTransform,
|
||||
getFileSystem,
|
||||
getInitializerApiJitTransform,
|
||||
getSourceFileOrError,
|
||||
isDocEntryWithSourceInfo,
|
||||
isLocalCompilationDiagnostics,
|
||||
isLocalRelativePath,
|
||||
isRoot,
|
||||
isRooted,
|
||||
isTsDiagnostic,
|
||||
join,
|
||||
ngErrorCode,
|
||||
performCompilation,
|
||||
readConfiguration,
|
||||
relative,
|
||||
relativeFrom,
|
||||
resolve,
|
||||
setFileSystem,
|
||||
toRelativeImport
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+510
@@ -0,0 +1,510 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
FatalLinkerError,
|
||||
FileLinker,
|
||||
LinkerEnvironment,
|
||||
assert,
|
||||
isFatalLinkerError
|
||||
} from "../../chunk-FLWAEX6T.js";
|
||||
import {
|
||||
ConsoleLogger,
|
||||
LogLevel
|
||||
} from "../../chunk-6HOSNZU5.js";
|
||||
import "../../chunk-HYJ2H3FU.js";
|
||||
import "../../chunk-CSUVPNMK.js";
|
||||
import {
|
||||
NodeJSFileSystem
|
||||
} from "../../chunk-XYYEESKY.js";
|
||||
import "../../chunk-G7GFT6BU.js";
|
||||
|
||||
// packages/compiler-cli/linker/babel/src/es2015_linker_plugin.js
|
||||
import { types as t4 } from "@babel/core";
|
||||
|
||||
// packages/compiler-cli/linker/babel/src/ast/babel_ast_factory.js
|
||||
import { types as t } from "@babel/core";
|
||||
var BabelAstFactory = class {
|
||||
sourceUrl;
|
||||
constructor(sourceUrl) {
|
||||
this.sourceUrl = sourceUrl;
|
||||
}
|
||||
attachComments(statement, leadingComments) {
|
||||
for (let i = leadingComments.length - 1; i >= 0; i--) {
|
||||
const comment = leadingComments[i];
|
||||
t.addComment(statement, "leading", comment.toString(), !comment.multiline);
|
||||
}
|
||||
}
|
||||
createArrayLiteral = t.arrayExpression;
|
||||
createAssignment(target, operator, value) {
|
||||
assert(target, isLExpression, "must be a left hand side expression");
|
||||
return t.assignmentExpression(operator, target, value);
|
||||
}
|
||||
createBinaryExpression(leftOperand, operator, rightOperand) {
|
||||
switch (operator) {
|
||||
case "&&":
|
||||
case "||":
|
||||
case "??":
|
||||
return t.logicalExpression(operator, leftOperand, rightOperand);
|
||||
case "=":
|
||||
case "+=":
|
||||
case "-=":
|
||||
case "*=":
|
||||
case "/=":
|
||||
case "%=":
|
||||
case "**=":
|
||||
case "&&=":
|
||||
case "||=":
|
||||
case "??=":
|
||||
throw new Error(`Unexpected assignment operator ${operator}`);
|
||||
default:
|
||||
return t.binaryExpression(operator, leftOperand, rightOperand);
|
||||
}
|
||||
}
|
||||
createBlock = t.blockStatement;
|
||||
createCallExpression(callee, args, pure) {
|
||||
const call = t.callExpression(callee, args);
|
||||
if (pure) {
|
||||
t.addComment(
|
||||
call,
|
||||
"leading",
|
||||
" @__PURE__ ",
|
||||
/* line */
|
||||
false
|
||||
);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
createConditional = t.conditionalExpression;
|
||||
createElementAccess(expression, element) {
|
||||
return t.memberExpression(
|
||||
expression,
|
||||
element,
|
||||
/* computed */
|
||||
true
|
||||
);
|
||||
}
|
||||
createExpressionStatement = t.expressionStatement;
|
||||
createSpreadElement(expression) {
|
||||
return t.spreadElement(expression);
|
||||
}
|
||||
createFunctionDeclaration(functionName, parameters, body) {
|
||||
assert(body, t.isBlockStatement, "a block");
|
||||
return t.functionDeclaration(t.identifier(functionName), parameters.map((param) => t.identifier(param)), body);
|
||||
}
|
||||
createArrowFunctionExpression(parameters, body) {
|
||||
if (t.isStatement(body)) {
|
||||
assert(body, t.isBlockStatement, "a block");
|
||||
}
|
||||
return t.arrowFunctionExpression(parameters.map((param) => t.identifier(param)), body);
|
||||
}
|
||||
createFunctionExpression(functionName, parameters, body) {
|
||||
assert(body, t.isBlockStatement, "a block");
|
||||
const name = functionName !== null ? t.identifier(functionName) : null;
|
||||
return t.functionExpression(name, parameters.map((param) => t.identifier(param)), body);
|
||||
}
|
||||
createIdentifier = t.identifier;
|
||||
createIfStatement = t.ifStatement;
|
||||
createDynamicImport(url) {
|
||||
return this.createCallExpression(
|
||||
t.import(),
|
||||
[typeof url === "string" ? t.stringLiteral(url) : url],
|
||||
false
|
||||
/* pure */
|
||||
);
|
||||
}
|
||||
createLiteral(value) {
|
||||
if (typeof value === "string") {
|
||||
return t.stringLiteral(value);
|
||||
} else if (typeof value === "number") {
|
||||
return t.numericLiteral(value);
|
||||
} else if (typeof value === "boolean") {
|
||||
return t.booleanLiteral(value);
|
||||
} else if (value === void 0) {
|
||||
return t.identifier("undefined");
|
||||
} else if (value === null) {
|
||||
return t.nullLiteral();
|
||||
} else {
|
||||
throw new Error(`Invalid literal: ${value} (${typeof value})`);
|
||||
}
|
||||
}
|
||||
createNewExpression(expression, args) {
|
||||
return t.newExpression(expression, args);
|
||||
}
|
||||
createObjectLiteral(properties) {
|
||||
return t.objectExpression(properties.map((prop) => {
|
||||
if (prop.kind === "spread") {
|
||||
return t.spreadElement(prop.expression);
|
||||
}
|
||||
const key = prop.quoted ? t.stringLiteral(prop.propertyName) : t.identifier(prop.propertyName);
|
||||
return t.objectProperty(key, prop.value);
|
||||
}));
|
||||
}
|
||||
createParenthesizedExpression = t.parenthesizedExpression;
|
||||
createPropertyAccess(expression, propertyName) {
|
||||
return t.memberExpression(
|
||||
expression,
|
||||
t.identifier(propertyName),
|
||||
/* computed */
|
||||
false
|
||||
);
|
||||
}
|
||||
createReturnStatement(expression) {
|
||||
return t.returnStatement(expression);
|
||||
}
|
||||
createTaggedTemplate(tag, template) {
|
||||
return t.taggedTemplateExpression(tag, this.createTemplateLiteral(template));
|
||||
}
|
||||
createTemplateLiteral(template) {
|
||||
const elements = template.elements.map((element, i) => this.setSourceMapRange(t.templateElement(element, i === template.elements.length - 1), element.range));
|
||||
return t.templateLiteral(elements, template.expressions);
|
||||
}
|
||||
createThrowStatement = t.throwStatement;
|
||||
createTypeOfExpression(expression) {
|
||||
return t.unaryExpression("typeof", expression);
|
||||
}
|
||||
createVoidExpression(expression) {
|
||||
return t.unaryExpression("void", expression);
|
||||
}
|
||||
createUnaryExpression = t.unaryExpression;
|
||||
createVariableDeclaration(variableName, initializer, type) {
|
||||
return t.variableDeclaration(type, [
|
||||
t.variableDeclarator(t.identifier(variableName), initializer)
|
||||
]);
|
||||
}
|
||||
createRegularExpressionLiteral(body, flags) {
|
||||
return t.regExpLiteral(body, flags ?? void 0);
|
||||
}
|
||||
setSourceMapRange(node, sourceMapRange) {
|
||||
if (sourceMapRange === null) {
|
||||
return node;
|
||||
}
|
||||
node.loc = {
|
||||
// Add in the filename so that we can map to external template files.
|
||||
// Note that Babel gets confused if you specify a filename when it is the original source
|
||||
// file. This happens when the template is inline, in which case just use `undefined`.
|
||||
filename: sourceMapRange.url !== this.sourceUrl ? sourceMapRange.url : void 0,
|
||||
start: {
|
||||
line: sourceMapRange.start.line + 1,
|
||||
// lines are 1-based in Babel.
|
||||
column: sourceMapRange.start.column
|
||||
},
|
||||
end: {
|
||||
line: sourceMapRange.end.line + 1,
|
||||
// lines are 1-based in Babel.
|
||||
column: sourceMapRange.end.column
|
||||
}
|
||||
};
|
||||
node.start = sourceMapRange.start.offset;
|
||||
node.end = sourceMapRange.end.offset;
|
||||
return node;
|
||||
}
|
||||
};
|
||||
function isLExpression(expr) {
|
||||
return t.isLVal(expr);
|
||||
}
|
||||
|
||||
// packages/compiler-cli/linker/babel/src/ast/babel_ast_host.js
|
||||
import { types as t2 } from "@babel/core";
|
||||
var BabelAstHost = class {
|
||||
getSymbolName(node) {
|
||||
if (t2.isIdentifier(node)) {
|
||||
return node.name;
|
||||
} else if (t2.isMemberExpression(node) && t2.isIdentifier(node.property)) {
|
||||
return node.property.name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
isStringLiteral = t2.isStringLiteral;
|
||||
parseStringLiteral(str) {
|
||||
assert(str, t2.isStringLiteral, "a string literal");
|
||||
return str.value;
|
||||
}
|
||||
isNumericLiteral = t2.isNumericLiteral;
|
||||
parseNumericLiteral(num) {
|
||||
assert(num, t2.isNumericLiteral, "a numeric literal");
|
||||
return num.value;
|
||||
}
|
||||
isBooleanLiteral(bool) {
|
||||
return t2.isBooleanLiteral(bool) || isMinifiedBooleanLiteral(bool);
|
||||
}
|
||||
parseBooleanLiteral(bool) {
|
||||
if (t2.isBooleanLiteral(bool)) {
|
||||
return bool.value;
|
||||
} else if (isMinifiedBooleanLiteral(bool)) {
|
||||
return !bool.argument.value;
|
||||
} else {
|
||||
throw new FatalLinkerError(bool, "Unsupported syntax, expected a boolean literal.");
|
||||
}
|
||||
}
|
||||
isNull(node) {
|
||||
return t2.isNullLiteral(node);
|
||||
}
|
||||
isArrayLiteral = t2.isArrayExpression;
|
||||
parseArrayLiteral(array) {
|
||||
assert(array, t2.isArrayExpression, "an array literal");
|
||||
return array.elements.map((element) => {
|
||||
assert(element, isNotEmptyElement, "element in array not to be empty");
|
||||
assert(element, isNotSpreadElement, "element in array not to use spread syntax");
|
||||
return element;
|
||||
});
|
||||
}
|
||||
isObjectLiteral = t2.isObjectExpression;
|
||||
parseObjectLiteral(obj) {
|
||||
assert(obj, t2.isObjectExpression, "an object literal");
|
||||
const result = /* @__PURE__ */ new Map();
|
||||
for (const property of obj.properties) {
|
||||
assert(property, t2.isObjectProperty, "a property assignment");
|
||||
assert(property.value, t2.isExpression, "an expression");
|
||||
assert(property.key, isObjectExpressionPropertyName, "a property name");
|
||||
const key = t2.isIdentifier(property.key) ? property.key.name : property.key.value;
|
||||
result.set(`${key}`, property.value);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
isFunctionExpression(node) {
|
||||
return t2.isFunction(node) || t2.isArrowFunctionExpression(node);
|
||||
}
|
||||
parseReturnValue(fn) {
|
||||
assert(fn, this.isFunctionExpression, "a function");
|
||||
if (!t2.isBlockStatement(fn.body)) {
|
||||
return fn.body;
|
||||
}
|
||||
if (fn.body.body.length !== 1) {
|
||||
throw new FatalLinkerError(fn.body, "Unsupported syntax, expected a function body with a single return statement.");
|
||||
}
|
||||
const stmt = fn.body.body[0];
|
||||
assert(stmt, t2.isReturnStatement, "a function body with a single return statement");
|
||||
if (stmt.argument === null || stmt.argument === void 0) {
|
||||
throw new FatalLinkerError(stmt, "Unsupported syntax, expected function to return a value.");
|
||||
}
|
||||
return stmt.argument;
|
||||
}
|
||||
parseParameters(fn) {
|
||||
assert(fn, this.isFunctionExpression, "a function");
|
||||
return fn.params.map((param) => {
|
||||
assert(param, t2.isIdentifier, "an identifier");
|
||||
return param;
|
||||
});
|
||||
}
|
||||
isCallExpression = t2.isCallExpression;
|
||||
parseCallee(call) {
|
||||
assert(call, t2.isCallExpression, "a call expression");
|
||||
assert(call.callee, t2.isExpression, "an expression");
|
||||
return call.callee;
|
||||
}
|
||||
parseArguments(call) {
|
||||
assert(call, t2.isCallExpression, "a call expression");
|
||||
return call.arguments.map((arg) => {
|
||||
assert(arg, isNotSpreadArgument, "argument not to use spread syntax");
|
||||
assert(arg, t2.isExpression, "argument to be an expression");
|
||||
return arg;
|
||||
});
|
||||
}
|
||||
getRange(node) {
|
||||
if (node.loc == null || node.start == null || node.end == null) {
|
||||
throw new FatalLinkerError(node, "Unable to read range for node - it is missing location information.");
|
||||
}
|
||||
return {
|
||||
startLine: node.loc.start.line - 1,
|
||||
// Babel lines are 1-based
|
||||
startCol: node.loc.start.column,
|
||||
startPos: node.start,
|
||||
endPos: node.end
|
||||
};
|
||||
}
|
||||
};
|
||||
function isNotEmptyElement(e) {
|
||||
return e !== null;
|
||||
}
|
||||
function isNotSpreadElement(e) {
|
||||
return !t2.isSpreadElement(e);
|
||||
}
|
||||
function isObjectExpressionPropertyName(n) {
|
||||
return t2.isIdentifier(n) || t2.isStringLiteral(n) || t2.isNumericLiteral(n);
|
||||
}
|
||||
function isNotSpreadArgument(arg) {
|
||||
return !t2.isSpreadElement(arg);
|
||||
}
|
||||
function isMinifiedBooleanLiteral(node) {
|
||||
return t2.isUnaryExpression(node) && node.prefix && node.operator === "!" && t2.isNumericLiteral(node.argument) && (node.argument.value === 0 || node.argument.value === 1);
|
||||
}
|
||||
|
||||
// packages/compiler-cli/linker/babel/src/babel_declaration_scope.js
|
||||
import { types as t3 } from "@babel/core";
|
||||
var BabelDeclarationScope = class {
|
||||
declarationScope;
|
||||
/**
|
||||
* Construct a new `BabelDeclarationScope`.
|
||||
*
|
||||
* @param declarationScope the Babel scope containing the declaration call expression.
|
||||
*/
|
||||
constructor(declarationScope) {
|
||||
this.declarationScope = declarationScope;
|
||||
}
|
||||
/**
|
||||
* Compute the Babel `NodePath` that can be used to reference the lexical scope where any
|
||||
* shared constant statements would be inserted.
|
||||
*
|
||||
* There will only be a shared constant scope if the expression is in an ECMAScript module, or a
|
||||
* UMD module. Otherwise `null` is returned to indicate that constant statements must be emitted
|
||||
* locally to the generated linked definition, to avoid polluting the global scope.
|
||||
*
|
||||
* @param expression the expression that points to the Angular core framework import.
|
||||
*/
|
||||
getConstantScopeRef(expression) {
|
||||
let bindingExpression = expression;
|
||||
while (t3.isMemberExpression(bindingExpression)) {
|
||||
bindingExpression = bindingExpression.object;
|
||||
}
|
||||
if (!t3.isIdentifier(bindingExpression)) {
|
||||
return null;
|
||||
}
|
||||
const binding = this.declarationScope.getBinding(bindingExpression.name);
|
||||
if (binding === void 0) {
|
||||
return null;
|
||||
}
|
||||
const path = binding.scope.path;
|
||||
if (!path.isFunctionDeclaration() && !path.isFunctionExpression() && !(path.isProgram() && path.node.sourceType === "module")) {
|
||||
return null;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/linker/babel/src/es2015_linker_plugin.js
|
||||
function createEs2015LinkerPlugin({ fileSystem, logger, ...options }) {
|
||||
let fileLinker = null;
|
||||
return {
|
||||
visitor: {
|
||||
Program: {
|
||||
/**
|
||||
* Create a new `FileLinker` as we enter each file (`t.Program` in Babel).
|
||||
*/
|
||||
enter(_, state) {
|
||||
assertNull(fileLinker);
|
||||
const file = state.file;
|
||||
const filename = file.opts.filename ?? file.opts.filenameRelative;
|
||||
if (!filename) {
|
||||
throw new Error("No filename (nor filenameRelative) provided by Babel. This is required for the linking of partially compiled directives and components.");
|
||||
}
|
||||
const sourceUrl = fileSystem.resolve(file.opts.cwd ?? ".", filename);
|
||||
const linkerEnvironment = LinkerEnvironment.create(fileSystem, logger, new BabelAstHost(), new BabelAstFactory(sourceUrl), options);
|
||||
fileLinker = new FileLinker(linkerEnvironment, sourceUrl, file.code);
|
||||
},
|
||||
/**
|
||||
* On exiting the file, insert any shared constant statements that were generated during
|
||||
* linking of the partial declarations.
|
||||
*/
|
||||
exit() {
|
||||
assertNotNull(fileLinker);
|
||||
for (const { constantScope, statements } of fileLinker.getConstantStatements()) {
|
||||
insertStatements(constantScope, statements);
|
||||
}
|
||||
fileLinker = null;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Test each call expression to see if it is a partial declaration; it if is then replace it
|
||||
* with the results of linking the declaration.
|
||||
*/
|
||||
CallExpression(call, state) {
|
||||
if (fileLinker === null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const calleeName = getCalleeName(call);
|
||||
if (calleeName === null) {
|
||||
return;
|
||||
}
|
||||
const args = call.node.arguments;
|
||||
if (!fileLinker.isPartialDeclaration(calleeName) || !isExpressionArray(args)) {
|
||||
return;
|
||||
}
|
||||
const declarationScope = new BabelDeclarationScope(call.scope);
|
||||
const replacement = fileLinker.linkPartialDeclaration(calleeName, args, declarationScope);
|
||||
call.replaceWith(replacement);
|
||||
} catch (e) {
|
||||
const node = isFatalLinkerError(e) ? e.node : call.node;
|
||||
throw buildCodeFrameError(state.file, e.message, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function insertStatements(path, statements) {
|
||||
if (path.isProgram()) {
|
||||
insertIntoProgram(path, statements);
|
||||
} else {
|
||||
insertIntoFunction(path, statements);
|
||||
}
|
||||
}
|
||||
function insertIntoFunction(fn, statements) {
|
||||
const body = fn.get("body");
|
||||
body.unshiftContainer("body", statements);
|
||||
}
|
||||
function insertIntoProgram(program, statements) {
|
||||
const body = program.get("body");
|
||||
const insertBeforeIndex = body.findIndex((statement) => !statement.isImportDeclaration());
|
||||
if (insertBeforeIndex === -1) {
|
||||
program.unshiftContainer("body", statements);
|
||||
} else {
|
||||
body[insertBeforeIndex].insertBefore(statements);
|
||||
}
|
||||
}
|
||||
function getCalleeName(call) {
|
||||
const callee = call.node.callee;
|
||||
if (t4.isIdentifier(callee)) {
|
||||
return callee.name;
|
||||
} else if (t4.isMemberExpression(callee) && t4.isIdentifier(callee.property)) {
|
||||
return callee.property.name;
|
||||
} else if (t4.isMemberExpression(callee) && t4.isStringLiteral(callee.property)) {
|
||||
return callee.property.value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function isExpressionArray(nodes) {
|
||||
return nodes.every((node) => t4.isExpression(node));
|
||||
}
|
||||
function assertNull(obj) {
|
||||
if (obj !== null) {
|
||||
throw new Error("BUG - expected `obj` to be null");
|
||||
}
|
||||
}
|
||||
function assertNotNull(obj) {
|
||||
if (obj === null) {
|
||||
throw new Error("BUG - expected `obj` not to be null");
|
||||
}
|
||||
}
|
||||
function buildCodeFrameError(file, message, node) {
|
||||
const filename = file.opts.filename || "(unknown file)";
|
||||
const error = file.hub.buildError(node, message);
|
||||
return `${filename}: ${error.message}`;
|
||||
}
|
||||
|
||||
// packages/compiler-cli/linker/babel/src/babel_plugin.js
|
||||
function defaultLinkerPlugin(api, options) {
|
||||
api.assertVersion(7);
|
||||
return createEs2015LinkerPlugin({
|
||||
...options,
|
||||
fileSystem: new NodeJSFileSystem(),
|
||||
logger: new ConsoleLogger(LogLevel.info)
|
||||
});
|
||||
}
|
||||
|
||||
// packages/compiler-cli/linker/babel/index.ts
|
||||
var babel_default = defaultLinkerPlugin;
|
||||
export {
|
||||
createEs2015LinkerPlugin,
|
||||
babel_default as default
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
DEFAULT_LINKER_OPTIONS,
|
||||
FatalLinkerError,
|
||||
FileLinker,
|
||||
LinkerEnvironment,
|
||||
assert,
|
||||
isFatalLinkerError,
|
||||
needsLinking
|
||||
} from "../chunk-FLWAEX6T.js";
|
||||
import "../chunk-HYJ2H3FU.js";
|
||||
import "../chunk-CSUVPNMK.js";
|
||||
import "../chunk-G7GFT6BU.js";
|
||||
export {
|
||||
DEFAULT_LINKER_OPTIONS,
|
||||
FatalLinkerError,
|
||||
FileLinker,
|
||||
LinkerEnvironment,
|
||||
assert,
|
||||
isFatalLinkerError,
|
||||
needsLinking
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
ConsoleLogger,
|
||||
LogLevel
|
||||
} from "../chunk-6HOSNZU5.js";
|
||||
import {
|
||||
SourceFile,
|
||||
SourceFileLoader
|
||||
} from "../chunk-HYJ2H3FU.js";
|
||||
import {
|
||||
InvalidFileSystem,
|
||||
LogicalFileSystem,
|
||||
LogicalProjectPath,
|
||||
NgtscCompilerHost,
|
||||
absoluteFrom,
|
||||
absoluteFromSourceFile,
|
||||
basename,
|
||||
createFileSystemTsReadDirectoryFn,
|
||||
dirname,
|
||||
getFileSystem,
|
||||
getSourceFileOrError,
|
||||
isLocalRelativePath,
|
||||
isRoot,
|
||||
isRooted,
|
||||
join,
|
||||
relative,
|
||||
relativeFrom,
|
||||
resolve,
|
||||
setFileSystem,
|
||||
toRelativeImport
|
||||
} from "../chunk-CEBE44Q5.js";
|
||||
import {
|
||||
NodeJSFileSystem
|
||||
} from "../chunk-XYYEESKY.js";
|
||||
import "../chunk-G7GFT6BU.js";
|
||||
export {
|
||||
ConsoleLogger,
|
||||
InvalidFileSystem,
|
||||
LogLevel,
|
||||
LogicalFileSystem,
|
||||
LogicalProjectPath,
|
||||
NgtscCompilerHost,
|
||||
NodeJSFileSystem,
|
||||
SourceFile,
|
||||
SourceFileLoader,
|
||||
absoluteFrom,
|
||||
absoluteFromSourceFile,
|
||||
basename,
|
||||
createFileSystemTsReadDirectoryFn,
|
||||
dirname,
|
||||
getFileSystem,
|
||||
getSourceFileOrError,
|
||||
isLocalRelativePath,
|
||||
isRoot,
|
||||
isRooted,
|
||||
join,
|
||||
relative,
|
||||
relativeFrom,
|
||||
resolve,
|
||||
setFileSystem,
|
||||
toRelativeImport
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
DiagnosticCategoryLabel,
|
||||
NgCompiler
|
||||
} from "../chunk-PW54LIP6.js";
|
||||
import {
|
||||
CompilationMode,
|
||||
DtsMetadataReader,
|
||||
DynamicValue,
|
||||
FatalDiagnosticError,
|
||||
ImportManager,
|
||||
PartialEvaluator,
|
||||
PotentialImportKind,
|
||||
PotentialImportMode,
|
||||
Reference,
|
||||
ReferenceEmitKind,
|
||||
ReferenceEmitter,
|
||||
StaticInterpreter,
|
||||
SymbolKind,
|
||||
TypeScriptReflectionHost,
|
||||
createForwardRefResolver,
|
||||
extractDecoratorQueryMetadata,
|
||||
extractTemplate,
|
||||
findAngularDecorator,
|
||||
getAngularDecorators,
|
||||
getRootDirs,
|
||||
isShim,
|
||||
parseDecoratorInputTransformFunction,
|
||||
queryDecoratorNames,
|
||||
reflectObjectLiteral,
|
||||
unwrapExpression
|
||||
} from "../chunk-IG22BDVK.js";
|
||||
import "../chunk-CSUVPNMK.js";
|
||||
import {
|
||||
getFileSystem,
|
||||
isLocalRelativePath
|
||||
} from "../chunk-CEBE44Q5.js";
|
||||
import {
|
||||
NodeJSFileSystem
|
||||
} from "../chunk-XYYEESKY.js";
|
||||
import "../chunk-G7GFT6BU.js";
|
||||
export {
|
||||
CompilationMode,
|
||||
DiagnosticCategoryLabel,
|
||||
DtsMetadataReader,
|
||||
DynamicValue,
|
||||
FatalDiagnosticError,
|
||||
ImportManager,
|
||||
NgCompiler,
|
||||
NodeJSFileSystem,
|
||||
PartialEvaluator,
|
||||
PotentialImportKind,
|
||||
PotentialImportMode,
|
||||
Reference,
|
||||
ReferenceEmitKind,
|
||||
ReferenceEmitter,
|
||||
StaticInterpreter,
|
||||
SymbolKind,
|
||||
TypeScriptReflectionHost,
|
||||
createForwardRefResolver,
|
||||
extractDecoratorQueryMetadata,
|
||||
extractTemplate,
|
||||
findAngularDecorator,
|
||||
getAngularDecorators,
|
||||
getFileSystem,
|
||||
getRootDirs,
|
||||
isLocalRelativePath,
|
||||
isShim,
|
||||
parseDecoratorInputTransformFunction,
|
||||
queryDecoratorNames,
|
||||
reflectObjectLiteral,
|
||||
unwrapExpression
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+527
@@ -0,0 +1,527 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
ImportedSymbolsTracker,
|
||||
TypeScriptReflectionHost,
|
||||
getInitializerApiJitTransform
|
||||
} from "../chunk-IG22BDVK.js";
|
||||
import "../chunk-CSUVPNMK.js";
|
||||
import {
|
||||
InvalidFileSystem,
|
||||
absoluteFrom,
|
||||
basename,
|
||||
dirname,
|
||||
resolve,
|
||||
setFileSystem
|
||||
} from "../chunk-CEBE44Q5.js";
|
||||
import {
|
||||
NodeJSFileSystem
|
||||
} from "../chunk-XYYEESKY.js";
|
||||
import "../chunk-G7GFT6BU.js";
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.js
|
||||
var MockFileSystem = class {
|
||||
_isCaseSensitive;
|
||||
_fileTree = {};
|
||||
_cwd;
|
||||
constructor(_isCaseSensitive = false, cwd = "/") {
|
||||
this._isCaseSensitive = _isCaseSensitive;
|
||||
this._cwd = this.normalize(cwd);
|
||||
}
|
||||
isCaseSensitive() {
|
||||
return this._isCaseSensitive;
|
||||
}
|
||||
exists(path) {
|
||||
return this.findFromPath(path).entity !== null;
|
||||
}
|
||||
readFile(path) {
|
||||
const { entity } = this.findFromPath(path);
|
||||
if (isFile(entity)) {
|
||||
if (entity instanceof Uint8Array) {
|
||||
return new TextDecoder().decode(entity);
|
||||
}
|
||||
return entity.toString();
|
||||
} else {
|
||||
throw new MockFileSystemError("ENOENT", path, `File "${path}" does not exist.`);
|
||||
}
|
||||
}
|
||||
readFileBuffer(path) {
|
||||
const { entity } = this.findFromPath(path);
|
||||
if (isFile(entity)) {
|
||||
if (entity instanceof Uint8Array) {
|
||||
return entity;
|
||||
}
|
||||
const encoder = new TextEncoder();
|
||||
return encoder.encode(entity);
|
||||
} else {
|
||||
throw new MockFileSystemError("ENOENT", path, `File "${path}" does not exist.`);
|
||||
}
|
||||
}
|
||||
writeFile(path, data, exclusive = false) {
|
||||
const [folderPath, basename2] = this.splitIntoFolderAndFile(path);
|
||||
const { entity } = this.findFromPath(folderPath);
|
||||
if (entity === null || !isFolder(entity)) {
|
||||
throw new MockFileSystemError("ENOENT", path, `Unable to write file "${path}". The containing folder does not exist.`);
|
||||
}
|
||||
if (exclusive && entity[basename2] !== void 0) {
|
||||
throw new MockFileSystemError("EEXIST", path, `Unable to exclusively write file "${path}". The file already exists.`);
|
||||
}
|
||||
entity[basename2] = data;
|
||||
}
|
||||
removeFile(path) {
|
||||
const [folderPath, basename2] = this.splitIntoFolderAndFile(path);
|
||||
const { entity } = this.findFromPath(folderPath);
|
||||
if (entity === null || !isFolder(entity)) {
|
||||
throw new MockFileSystemError("ENOENT", path, `Unable to remove file "${path}". The containing folder does not exist.`);
|
||||
}
|
||||
if (isFolder(entity[basename2])) {
|
||||
throw new MockFileSystemError("EISDIR", path, `Unable to remove file "${path}". The path to remove is a folder.`);
|
||||
}
|
||||
delete entity[basename2];
|
||||
}
|
||||
symlink(target, path) {
|
||||
const [folderPath, basename2] = this.splitIntoFolderAndFile(path);
|
||||
const { entity } = this.findFromPath(folderPath);
|
||||
if (entity === null || !isFolder(entity)) {
|
||||
throw new MockFileSystemError("ENOENT", path, `Unable to create symlink at "${path}". The containing folder does not exist.`);
|
||||
}
|
||||
entity[basename2] = new SymLink(target);
|
||||
}
|
||||
readdir(path) {
|
||||
const { entity } = this.findFromPath(path);
|
||||
if (entity === null) {
|
||||
throw new MockFileSystemError("ENOENT", path, `Unable to read directory "${path}". It does not exist.`);
|
||||
}
|
||||
if (isFile(entity)) {
|
||||
throw new MockFileSystemError("ENOTDIR", path, `Unable to read directory "${path}". It is a file.`);
|
||||
}
|
||||
return Object.keys(entity);
|
||||
}
|
||||
lstat(path) {
|
||||
const { entity } = this.findFromPath(path);
|
||||
if (entity === null) {
|
||||
throw new MockFileSystemError("ENOENT", path, `File "${path}" does not exist.`);
|
||||
}
|
||||
return new MockFileStats(entity);
|
||||
}
|
||||
stat(path) {
|
||||
const { entity } = this.findFromPath(path, { followSymLinks: true });
|
||||
if (entity === null) {
|
||||
throw new MockFileSystemError("ENOENT", path, `File "${path}" does not exist.`);
|
||||
}
|
||||
return new MockFileStats(entity);
|
||||
}
|
||||
copyFile(from, to) {
|
||||
this.writeFile(to, this.readFile(from));
|
||||
}
|
||||
moveFile(from, to) {
|
||||
this.writeFile(to, this.readFile(from));
|
||||
const result = this.findFromPath(dirname(from));
|
||||
const folder = result.entity;
|
||||
const name = basename(from);
|
||||
delete folder[name];
|
||||
}
|
||||
ensureDir(path) {
|
||||
const segments = this.splitPath(path).map((segment) => this.getCanonicalPath(segment));
|
||||
segments[0] = "";
|
||||
if (segments.length > 1 && segments[segments.length - 1] === "") {
|
||||
segments.pop();
|
||||
}
|
||||
let current = this._fileTree;
|
||||
for (const segment of segments) {
|
||||
if (isFile(current[segment])) {
|
||||
throw new Error(`Folder already exists as a file.`);
|
||||
}
|
||||
if (!current[segment]) {
|
||||
current[segment] = {};
|
||||
}
|
||||
current = current[segment];
|
||||
}
|
||||
return current;
|
||||
}
|
||||
removeDeep(path) {
|
||||
const [folderPath, basename2] = this.splitIntoFolderAndFile(path);
|
||||
const { entity } = this.findFromPath(folderPath);
|
||||
if (entity === null || !isFolder(entity)) {
|
||||
throw new MockFileSystemError("ENOENT", path, `Unable to remove folder "${path}". The containing folder does not exist.`);
|
||||
}
|
||||
delete entity[basename2];
|
||||
}
|
||||
isRoot(path) {
|
||||
return this.dirname(path) === path;
|
||||
}
|
||||
extname(path) {
|
||||
const match = /.+(\.[^.]*)$/.exec(path);
|
||||
return match !== null ? match[1] : "";
|
||||
}
|
||||
realpath(filePath) {
|
||||
const result = this.findFromPath(filePath, { followSymLinks: true });
|
||||
if (result.entity === null) {
|
||||
throw new MockFileSystemError("ENOENT", filePath, `Unable to find the real path of "${filePath}". It does not exist.`);
|
||||
} else {
|
||||
return result.path;
|
||||
}
|
||||
}
|
||||
pwd() {
|
||||
return this._cwd;
|
||||
}
|
||||
chdir(path) {
|
||||
this._cwd = this.normalize(path);
|
||||
}
|
||||
getDefaultLibLocation() {
|
||||
let path = "node_modules/typescript/lib";
|
||||
let resolvedPath = this.resolve(path);
|
||||
const topLevelNodeModules = this.resolve("/" + path);
|
||||
while (resolvedPath !== topLevelNodeModules) {
|
||||
if (this.exists(resolvedPath)) {
|
||||
return resolvedPath;
|
||||
}
|
||||
path = "../" + path;
|
||||
resolvedPath = this.resolve(path);
|
||||
}
|
||||
return topLevelNodeModules;
|
||||
}
|
||||
dump() {
|
||||
const { entity } = this.findFromPath(this.resolve("/"));
|
||||
if (entity === null || !isFolder(entity)) {
|
||||
return {};
|
||||
}
|
||||
return this.cloneFolder(entity);
|
||||
}
|
||||
init(folder) {
|
||||
this.mount(this.resolve("/"), folder);
|
||||
}
|
||||
mount(path, folder) {
|
||||
if (this.exists(path)) {
|
||||
throw new Error(`Unable to mount in '${path}' as it already exists.`);
|
||||
}
|
||||
const mountFolder = this.ensureDir(path);
|
||||
this.copyInto(folder, mountFolder);
|
||||
}
|
||||
cloneFolder(folder) {
|
||||
const clone = {};
|
||||
this.copyInto(folder, clone);
|
||||
return clone;
|
||||
}
|
||||
copyInto(from, to) {
|
||||
for (const path in from) {
|
||||
const item = from[path];
|
||||
const canonicalPath = this.getCanonicalPath(path);
|
||||
if (isSymLink(item)) {
|
||||
to[canonicalPath] = new SymLink(this.getCanonicalPath(item.path));
|
||||
} else if (isFolder(item)) {
|
||||
to[canonicalPath] = this.cloneFolder(item);
|
||||
} else {
|
||||
to[canonicalPath] = from[path];
|
||||
}
|
||||
}
|
||||
}
|
||||
findFromPath(path, options) {
|
||||
const followSymLinks = !!options && options.followSymLinks;
|
||||
const segments = this.splitPath(path);
|
||||
if (segments.length > 1 && segments[segments.length - 1] === "") {
|
||||
segments.pop();
|
||||
}
|
||||
segments[0] = "";
|
||||
let current = this._fileTree;
|
||||
while (segments.length) {
|
||||
current = current[this.getCanonicalPath(segments.shift())];
|
||||
if (current === void 0) {
|
||||
return { path, entity: null };
|
||||
}
|
||||
if (segments.length > 0) {
|
||||
if (isFile(current)) {
|
||||
current = null;
|
||||
break;
|
||||
}
|
||||
if (isSymLink(current)) {
|
||||
return this.findFromPath(resolve(current.path, ...segments), { followSymLinks });
|
||||
}
|
||||
}
|
||||
if (isFile(current)) {
|
||||
break;
|
||||
}
|
||||
if (isSymLink(current)) {
|
||||
if (followSymLinks) {
|
||||
return this.findFromPath(resolve(current.path, ...segments), { followSymLinks });
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return { path, entity: current };
|
||||
}
|
||||
splitIntoFolderAndFile(path) {
|
||||
const segments = this.splitPath(this.getCanonicalPath(path));
|
||||
const file = segments.pop();
|
||||
return [path.substring(0, path.length - file.length - 1), file];
|
||||
}
|
||||
getCanonicalPath(p3) {
|
||||
return this.isCaseSensitive() ? p3 : p3.toLowerCase();
|
||||
}
|
||||
};
|
||||
var SymLink = class {
|
||||
path;
|
||||
constructor(path) {
|
||||
this.path = path;
|
||||
}
|
||||
};
|
||||
var MockFileStats = class {
|
||||
entity;
|
||||
constructor(entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
isFile() {
|
||||
return isFile(this.entity);
|
||||
}
|
||||
isDirectory() {
|
||||
return isFolder(this.entity);
|
||||
}
|
||||
isSymbolicLink() {
|
||||
return isSymLink(this.entity);
|
||||
}
|
||||
};
|
||||
var MockFileSystemError = class extends Error {
|
||||
code;
|
||||
path;
|
||||
constructor(code, path, message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
this.path = path;
|
||||
}
|
||||
};
|
||||
function isFile(item) {
|
||||
return item instanceof Uint8Array || typeof item === "string";
|
||||
}
|
||||
function isSymLink(item) {
|
||||
return item instanceof SymLink;
|
||||
}
|
||||
function isFolder(item) {
|
||||
return item !== null && !isFile(item) && !isSymLink(item);
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system_native.js
|
||||
import * as os from "os";
|
||||
var isWindows = os.platform?.() === "win32";
|
||||
var MockFileSystemNative = class extends MockFileSystem {
|
||||
constructor(cwd = "/") {
|
||||
super(void 0, cwd);
|
||||
}
|
||||
// Delegate to the real NodeJSFileSystem for these path related methods
|
||||
resolve(...paths) {
|
||||
return NodeJSFileSystem.prototype.resolve.call(this, this.pwd(), ...paths);
|
||||
}
|
||||
dirname(file) {
|
||||
return NodeJSFileSystem.prototype.dirname.call(this, file);
|
||||
}
|
||||
join(basePath, ...paths) {
|
||||
return NodeJSFileSystem.prototype.join.call(this, basePath, ...paths);
|
||||
}
|
||||
relative(from, to) {
|
||||
return NodeJSFileSystem.prototype.relative.call(this, from, to);
|
||||
}
|
||||
basename(filePath, extension) {
|
||||
return NodeJSFileSystem.prototype.basename.call(this, filePath, extension);
|
||||
}
|
||||
isCaseSensitive() {
|
||||
return NodeJSFileSystem.prototype.isCaseSensitive.call(this);
|
||||
}
|
||||
isRooted(path) {
|
||||
return NodeJSFileSystem.prototype.isRooted.call(this, path);
|
||||
}
|
||||
isRoot(path) {
|
||||
return NodeJSFileSystem.prototype.isRoot.call(this, path);
|
||||
}
|
||||
normalize(path) {
|
||||
if (isWindows) {
|
||||
path = path.replace(/^[\/\\]/i, "C:/");
|
||||
}
|
||||
return NodeJSFileSystem.prototype.normalize.call(this, path);
|
||||
}
|
||||
splitPath(path) {
|
||||
return path.split(/[\\\/]/);
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system_posix.js
|
||||
import * as p from "path";
|
||||
var MockFileSystemPosix = class extends MockFileSystem {
|
||||
resolve(...paths) {
|
||||
const resolved = p.posix.resolve(this.pwd(), ...paths);
|
||||
return this.normalize(resolved);
|
||||
}
|
||||
dirname(file) {
|
||||
return this.normalize(p.posix.dirname(file));
|
||||
}
|
||||
join(basePath, ...paths) {
|
||||
return this.normalize(p.posix.join(basePath, ...paths));
|
||||
}
|
||||
relative(from, to) {
|
||||
return this.normalize(p.posix.relative(from, to));
|
||||
}
|
||||
basename(filePath, extension) {
|
||||
return p.posix.basename(filePath, extension);
|
||||
}
|
||||
isRooted(path) {
|
||||
return path.startsWith("/");
|
||||
}
|
||||
splitPath(path) {
|
||||
return path.split("/");
|
||||
}
|
||||
normalize(path) {
|
||||
return path.replace(/^[a-z]:\//i, "/").replace(/\\/g, "/");
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system_windows.js
|
||||
import * as p2 from "path";
|
||||
var MockFileSystemWindows = class extends MockFileSystem {
|
||||
resolve(...paths) {
|
||||
const resolved = p2.win32.resolve(this.pwd(), ...paths);
|
||||
return this.normalize(resolved);
|
||||
}
|
||||
dirname(path) {
|
||||
return this.normalize(p2.win32.dirname(path));
|
||||
}
|
||||
join(basePath, ...paths) {
|
||||
return this.normalize(p2.win32.join(basePath, ...paths));
|
||||
}
|
||||
relative(from, to) {
|
||||
return this.normalize(p2.win32.relative(from, to));
|
||||
}
|
||||
basename(filePath, extension) {
|
||||
return p2.win32.basename(filePath, extension);
|
||||
}
|
||||
isRooted(path) {
|
||||
return /^([A-Z]:)?([\\\/]|$)/i.test(path);
|
||||
}
|
||||
splitPath(path) {
|
||||
return path.split(/[\\\/]/);
|
||||
}
|
||||
normalize(path) {
|
||||
return path.replace(/^[\/\\]/i, "C:/").replace(/\\/g, "/");
|
||||
}
|
||||
};
|
||||
|
||||
// packages/compiler-cli/src/ngtsc/file_system/testing/src/test_helper.js
|
||||
import ts from "typescript";
|
||||
var FS_NATIVE = "Native";
|
||||
var FS_OS_X = "OS/X";
|
||||
var FS_UNIX = "Unix";
|
||||
var FS_WINDOWS = "Windows";
|
||||
var FS_ALL = [FS_OS_X, FS_WINDOWS, FS_UNIX, FS_NATIVE];
|
||||
function runInEachFileSystemFn(callback) {
|
||||
FS_ALL.forEach((os2) => runInFileSystem(os2, callback, false));
|
||||
}
|
||||
var counter = 0;
|
||||
function runInFileSystem(os2, callback, error) {
|
||||
describe(`<<FileSystem: ${os2}>>/${counter++}`, () => {
|
||||
beforeEach(() => initMockFileSystem(os2));
|
||||
afterEach(() => setFileSystem(new InvalidFileSystem()));
|
||||
callback(os2);
|
||||
if (error) {
|
||||
afterAll(() => {
|
||||
throw new Error(`runInFileSystem limited to ${os2}, cannot pass`);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
var runInEachFileSystem = runInEachFileSystemFn;
|
||||
runInEachFileSystem.native = (callback) => runInFileSystem(FS_NATIVE, callback, true);
|
||||
runInEachFileSystem.osX = (callback) => runInFileSystem(FS_OS_X, callback, true);
|
||||
runInEachFileSystem.unix = (callback) => runInFileSystem(FS_UNIX, callback, true);
|
||||
runInEachFileSystem.windows = (callback) => runInFileSystem(FS_WINDOWS, callback, true);
|
||||
function initMockFileSystem(os2, cwd) {
|
||||
const fs = createMockFileSystem(os2, cwd);
|
||||
setFileSystem(fs);
|
||||
monkeyPatchTypeScript(fs);
|
||||
return fs;
|
||||
}
|
||||
function createMockFileSystem(os2, cwd) {
|
||||
switch (os2) {
|
||||
case "OS/X":
|
||||
return new MockFileSystemPosix(
|
||||
/* isCaseSensitive */
|
||||
false,
|
||||
cwd
|
||||
);
|
||||
case "Unix":
|
||||
return new MockFileSystemPosix(
|
||||
/* isCaseSensitive */
|
||||
true,
|
||||
cwd
|
||||
);
|
||||
case "Windows":
|
||||
return new MockFileSystemWindows(
|
||||
/* isCaseSensitive*/
|
||||
false,
|
||||
cwd
|
||||
);
|
||||
case "Native":
|
||||
return new MockFileSystemNative(cwd);
|
||||
default:
|
||||
throw new Error("FileSystem not supported");
|
||||
}
|
||||
}
|
||||
function monkeyPatchTypeScript(fs) {
|
||||
ts.sys.fileExists = (path) => {
|
||||
const absPath = fs.resolve(path);
|
||||
return fs.exists(absPath) && fs.stat(absPath).isFile();
|
||||
};
|
||||
ts.sys.getCurrentDirectory = () => fs.pwd();
|
||||
ts.sys.getDirectories = getDirectories;
|
||||
ts.sys.readFile = fs.readFile.bind(fs);
|
||||
ts.sys.resolvePath = fs.resolve.bind(fs);
|
||||
ts.sys.writeFile = fs.writeFile.bind(fs);
|
||||
ts.sys.directoryExists = directoryExists;
|
||||
ts.sys.readDirectory = readDirectory;
|
||||
function getDirectories(path) {
|
||||
return fs.readdir(absoluteFrom(path)).filter((p3) => fs.stat(fs.resolve(path, p3)).isDirectory());
|
||||
}
|
||||
function getFileSystemEntries(path) {
|
||||
const files = [];
|
||||
const directories = [];
|
||||
const absPath = fs.resolve(path);
|
||||
const entries = fs.readdir(absPath);
|
||||
for (const entry of entries) {
|
||||
if (entry == "." || entry === "..") {
|
||||
continue;
|
||||
}
|
||||
const absPath2 = fs.resolve(path, entry);
|
||||
const stat = fs.stat(absPath2);
|
||||
if (stat.isDirectory()) {
|
||||
directories.push(absPath2);
|
||||
} else if (stat.isFile()) {
|
||||
files.push(absPath2);
|
||||
}
|
||||
}
|
||||
return { files, directories };
|
||||
}
|
||||
function realPath(path) {
|
||||
return fs.realpath(fs.resolve(path));
|
||||
}
|
||||
function directoryExists(path) {
|
||||
const absPath = fs.resolve(path);
|
||||
return fs.exists(absPath) && fs.stat(absPath).isDirectory();
|
||||
}
|
||||
const tsMatchFiles = ts.matchFiles;
|
||||
function readDirectory(path, extensions, excludes, includes, depth) {
|
||||
return tsMatchFiles(path, extensions, excludes, includes, fs.isCaseSensitive(), fs.pwd(), depth, getFileSystemEntries, realPath, directoryExists);
|
||||
}
|
||||
}
|
||||
export {
|
||||
ImportedSymbolsTracker,
|
||||
MockFileSystem,
|
||||
TypeScriptReflectionHost,
|
||||
getInitializerApiJitTransform,
|
||||
initMockFileSystem
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
angularJitApplicationTransform
|
||||
} from "../chunk-IG22BDVK.js";
|
||||
import "../chunk-CSUVPNMK.js";
|
||||
import "../chunk-CEBE44Q5.js";
|
||||
import "../chunk-XYYEESKY.js";
|
||||
import "../chunk-G7GFT6BU.js";
|
||||
|
||||
// packages/compiler-cli/private/tooling.ts
|
||||
var GLOBAL_DEFS_FOR_TERSER = {
|
||||
ngDevMode: false,
|
||||
ngI18nClosureMode: false
|
||||
};
|
||||
var GLOBAL_DEFS_FOR_TERSER_WITH_AOT = {
|
||||
...GLOBAL_DEFS_FOR_TERSER,
|
||||
ngJitMode: false
|
||||
};
|
||||
var constructorParametersDownlevelTransform = (program, isCore = false) => {
|
||||
return angularJitApplicationTransform(program, isCore);
|
||||
};
|
||||
export {
|
||||
GLOBAL_DEFS_FOR_TERSER,
|
||||
GLOBAL_DEFS_FOR_TERSER_WITH_AOT,
|
||||
constructorParametersDownlevelTransform
|
||||
};
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
main,
|
||||
readCommandLineAndConfiguration
|
||||
} from "../../chunk-WBUBKNAO.js";
|
||||
import {
|
||||
EmitFlags
|
||||
} from "../../chunk-VO3Q626H.js";
|
||||
import "../../chunk-PW54LIP6.js";
|
||||
import "../../chunk-IG22BDVK.js";
|
||||
import "../../chunk-CSUVPNMK.js";
|
||||
import {
|
||||
setFileSystem
|
||||
} from "../../chunk-CEBE44Q5.js";
|
||||
import {
|
||||
NodeJSFileSystem
|
||||
} from "../../chunk-XYYEESKY.js";
|
||||
import "../../chunk-G7GFT6BU.js";
|
||||
|
||||
// packages/compiler-cli/src/bin/ng_xi18n.ts
|
||||
import "reflect-metadata";
|
||||
|
||||
// packages/compiler-cli/src/extract_i18n.js
|
||||
import yargs from "yargs";
|
||||
function mainXi18n(args2, consoleError = console.error) {
|
||||
const config = readXi18nCommandLineAndConfiguration(args2);
|
||||
return main(args2, consoleError, config, void 0, void 0, void 0);
|
||||
}
|
||||
function readXi18nCommandLineAndConfiguration(args2) {
|
||||
const options = {};
|
||||
const parsedArgs = yargs(args2).option("i18nFormat", { type: "string" }).option("locale", { type: "string" }).option("outFile", { type: "string" }).parseSync();
|
||||
if (parsedArgs.outFile)
|
||||
options.i18nOutFile = parsedArgs.outFile;
|
||||
if (parsedArgs.i18nFormat)
|
||||
options.i18nOutFormat = parsedArgs.i18nFormat;
|
||||
if (parsedArgs.locale)
|
||||
options.i18nOutLocale = parsedArgs.locale;
|
||||
const config = readCommandLineAndConfiguration(args2, options, [
|
||||
"outFile",
|
||||
"i18nFormat",
|
||||
"locale"
|
||||
]);
|
||||
return { ...config, emitFlags: EmitFlags.I18nBundle };
|
||||
}
|
||||
|
||||
// packages/compiler-cli/src/bin/ng_xi18n.ts
|
||||
process.title = "Angular i18n Message Extractor (ng-xi18n)";
|
||||
var args = process.argv.slice(2);
|
||||
setFileSystem(new NodeJSFileSystem());
|
||||
process.exitCode = mainXi18n(args);
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import {createRequire as __cjsCompatRequire} from 'module';
|
||||
const require = __cjsCompatRequire(import.meta.url);
|
||||
|
||||
import {
|
||||
main
|
||||
} from "../../chunk-WBUBKNAO.js";
|
||||
import "../../chunk-VO3Q626H.js";
|
||||
import "../../chunk-PW54LIP6.js";
|
||||
import "../../chunk-IG22BDVK.js";
|
||||
import "../../chunk-CSUVPNMK.js";
|
||||
import {
|
||||
setFileSystem
|
||||
} from "../../chunk-CEBE44Q5.js";
|
||||
import {
|
||||
NodeJSFileSystem
|
||||
} from "../../chunk-XYYEESKY.js";
|
||||
import "../../chunk-G7GFT6BU.js";
|
||||
|
||||
// packages/compiler-cli/src/bin/ngc.ts
|
||||
import "reflect-metadata";
|
||||
async function runNgcComamnd() {
|
||||
process.title = "Angular Compiler (ngc)";
|
||||
const args = process.argv.slice(2);
|
||||
setFileSystem(new NodeJSFileSystem());
|
||||
process.exitCode = main(args, void 0, void 0, void 0, void 0, void 0);
|
||||
}
|
||||
runNgcComamnd().catch((e) => {
|
||||
console.error(e);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google LLC All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
Reference in New Issue
Block a user