mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Refactor declaration emitter into declaration transformer (#21930)
* Refactor declaration emitter into declaration transformer * Slight cleanup from code review feedback * Incorporate fix for new test * Swaths of PR feedback * Merge public methods * Per-file output * Preserve input import ordering more often * Unify jsdoc comment start detection under more lenient rule * Move to per-file transformations to reduce the memory that msut be retained * Fix typo
This commit is contained in:
1 parent
162a273e43
commit
19ec83fcdf
124 files changed
+2656
-2729
No files matched your search
+32
-19
@@ -3684,10 +3684,6 @@ namespace ts {
|
||||
isExternalModuleAugmentation(node.parent.parent);
|
||||
}
|
||||
|
||||
function literalTypeToString(type: LiteralType) {
|
||||
return type.flags & TypeFlags.StringLiteral ? '"' + escapeString((<StringLiteralType>type).value) + '"' : "" + (<NumberLiteralType>type).value;
|
||||
}
|
||||
|
||||
interface NodeBuilderContext {
|
||||
enclosingDeclaration: Node | undefined;
|
||||
flags: NodeBuilderFlags | undefined;
|
||||
@@ -3748,7 +3744,7 @@ namespace ts {
|
||||
return symbolName(symbol);
|
||||
}
|
||||
|
||||
function isDeclarationVisible(node: Declaration): boolean {
|
||||
function isDeclarationVisible(node: Declaration | AnyImportSyntax): boolean {
|
||||
if (node) {
|
||||
const links = getNodeLinks(node);
|
||||
if (links.isVisible === undefined) {
|
||||
@@ -25497,6 +25493,7 @@ namespace ts {
|
||||
|
||||
function isImplementationOfOverload(node: SignatureDeclaration) {
|
||||
if (nodeIsPresent((node as FunctionLikeDeclaration).body)) {
|
||||
if (isGetAccessor(node) || isSetAccessor(node)) return false; // Get or set accessors can never be overload implementations, but can have up to 2 signatures
|
||||
const symbol = getSymbolOfNode(node);
|
||||
const signaturesOfSymbol = getSignaturesOfSymbol(symbol);
|
||||
// If this function body corresponds to function with multiple signature, it is implementation of overload
|
||||
@@ -25636,7 +25633,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: EmitTextWriter) {
|
||||
function createTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker, addUndefined?: boolean) {
|
||||
declaration = getParseTreeNode(declaration, isVariableLikeOrAccessor);
|
||||
if (!declaration) {
|
||||
return createToken(SyntaxKind.AnyKeyword) as KeywordTypeNode;
|
||||
}
|
||||
// Get type of the symbol if this is the valid symbol otherwise get type at location
|
||||
const symbol = getSymbolOfNode(declaration);
|
||||
let type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature))
|
||||
@@ -25644,22 +25645,30 @@ namespace ts {
|
||||
: unknownType;
|
||||
if (type.flags & TypeFlags.UniqueESSymbol &&
|
||||
type.symbol === symbol) {
|
||||
flags |= TypeFormatFlags.AllowUniqueESSymbolType;
|
||||
flags |= NodeBuilderFlags.AllowUniqueESSymbolType;
|
||||
}
|
||||
if (flags & TypeFormatFlags.AddUndefined) {
|
||||
if (addUndefined) {
|
||||
type = getOptionalType(type);
|
||||
}
|
||||
typeToString(type, enclosingDeclaration, flags | TypeFormatFlags.MultilineObjectLiterals, writer);
|
||||
return nodeBuilder.typeToTypeNode(type, enclosingDeclaration, flags | NodeBuilderFlags.MultilineObjectLiterals, tracker);
|
||||
}
|
||||
|
||||
function writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: EmitTextWriter) {
|
||||
function createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker) {
|
||||
signatureDeclaration = getParseTreeNode(signatureDeclaration, isFunctionLike);
|
||||
if (!signatureDeclaration) {
|
||||
return createToken(SyntaxKind.AnyKeyword) as KeywordTypeNode;
|
||||
}
|
||||
const signature = getSignatureFromDeclaration(signatureDeclaration);
|
||||
typeToString(getReturnTypeOfSignature(signature), enclosingDeclaration, flags | TypeFormatFlags.MultilineObjectLiterals, writer);
|
||||
return nodeBuilder.typeToTypeNode(getReturnTypeOfSignature(signature), enclosingDeclaration, flags | NodeBuilderFlags.MultilineObjectLiterals, tracker);
|
||||
}
|
||||
|
||||
function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: EmitTextWriter) {
|
||||
function createTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker) {
|
||||
expr = getParseTreeNode(expr, isExpression);
|
||||
if (!expr) {
|
||||
return createToken(SyntaxKind.AnyKeyword) as KeywordTypeNode;
|
||||
}
|
||||
const type = getWidenedType(getRegularTypeOfExpression(expr));
|
||||
typeToString(type, enclosingDeclaration, flags | TypeFormatFlags.MultilineObjectLiterals, writer);
|
||||
return nodeBuilder.typeToTypeNode(type, enclosingDeclaration, flags | NodeBuilderFlags.MultilineObjectLiterals, tracker);
|
||||
}
|
||||
|
||||
function hasGlobalName(name: string): boolean {
|
||||
@@ -25707,9 +25716,13 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: EmitTextWriter) {
|
||||
function literalTypeToNode(type: LiteralType): Expression {
|
||||
return createLiteral(type.value);
|
||||
}
|
||||
|
||||
function createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration) {
|
||||
const type = getTypeOfSymbol(getSymbolOfNode(node));
|
||||
writer.writeStringLiteral(literalTypeToString(<LiteralType>type));
|
||||
return literalTypeToNode(<LiteralType>type);
|
||||
}
|
||||
|
||||
function createResolver(): EmitResolver {
|
||||
@@ -25753,9 +25766,10 @@ namespace ts {
|
||||
isImplementationOfOverload,
|
||||
isRequiredInitializedParameter,
|
||||
isOptionalUninitializedParameterProperty,
|
||||
writeTypeOfDeclaration,
|
||||
writeReturnTypeOfSignatureDeclaration,
|
||||
writeTypeOfExpression,
|
||||
createTypeOfDeclaration,
|
||||
createReturnTypeOfSignatureDeclaration,
|
||||
createTypeOfExpression,
|
||||
createLiteralConstValue,
|
||||
isSymbolAccessible,
|
||||
isEntityNameVisible,
|
||||
getConstantValue: node => {
|
||||
@@ -25777,7 +25791,6 @@ namespace ts {
|
||||
const symbol = node && getSymbolOfNode(node);
|
||||
return !!(symbol && getCheckFlags(symbol) & CheckFlags.Late);
|
||||
},
|
||||
writeLiteralConstValue,
|
||||
getJsxFactoryEntity: location => location ? (getJsxNamespace(location), (getSourceFileOfNode(location).localJsxFactory || _jsxFactoryEntity)) : _jsxFactoryEntity
|
||||
};
|
||||
|
||||
|
||||
@@ -260,7 +260,15 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function shouldWriteComment(text: string, pos: number) {
|
||||
if (printerOptions.onlyPrintJsDocStyle) {
|
||||
return (isJSDocLikeText(text, pos) || isPinnedComment(text, pos));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function emitLeadingComment(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) {
|
||||
if (!shouldWriteComment(currentText, commentPos)) return;
|
||||
if (!hasWrittenComment) {
|
||||
emitNewLineBeforeLeadingCommentOfPosition(currentLineMap, writer, rangePos, commentPos);
|
||||
hasWrittenComment = true;
|
||||
@@ -292,6 +300,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function emitTrailingComment(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean) {
|
||||
if (!shouldWriteComment(currentText, commentPos)) return;
|
||||
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
|
||||
if (!writer.isAtStartOfLine()) {
|
||||
writer.write(" ");
|
||||
@@ -404,6 +413,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function writeComment(text: string, lineMap: number[], writer: EmitTextWriter, commentPos: number, commentEnd: number, newLine: string) {
|
||||
if (!shouldWriteComment(currentText, commentPos)) return;
|
||||
if (emitPos) emitPos(commentPos);
|
||||
writeCommentRange(text, lineMap, writer, commentPos, commentEnd, newLine);
|
||||
if (emitPos) emitPos(commentEnd);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+135
-80
@@ -1,6 +1,5 @@
|
||||
/// <reference path="checker.ts" />
|
||||
/// <reference path="transformer.ts" />
|
||||
/// <reference path="declarationEmitter.ts" />
|
||||
/// <reference path="sourcemap.ts" />
|
||||
/// <reference path="comments.ts" />
|
||||
|
||||
@@ -18,18 +17,16 @@ namespace ts {
|
||||
* Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit.
|
||||
*/
|
||||
export function forEachEmittedFile<T>(
|
||||
host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle, emitOnlyDtsFiles: boolean) => T,
|
||||
sourceFilesOrTargetSourceFile?: SourceFile[] | SourceFile,
|
||||
host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) => T,
|
||||
sourceFilesOrTargetSourceFile?: ReadonlyArray<SourceFile> | SourceFile,
|
||||
emitOnlyDtsFiles?: boolean) {
|
||||
|
||||
const sourceFiles = isArray(sourceFilesOrTargetSourceFile) ? sourceFilesOrTargetSourceFile : getSourceFilesToEmit(host, sourceFilesOrTargetSourceFile);
|
||||
const options = host.getCompilerOptions();
|
||||
if (options.outFile || options.out) {
|
||||
if (sourceFiles.length) {
|
||||
const jsFilePath = options.outFile || options.out;
|
||||
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
|
||||
const declarationFilePath = options.declaration ? removeFileExtension(jsFilePath) + Extension.Dts : "";
|
||||
const result = action({ jsFilePath, sourceMapFilePath, declarationFilePath }, createBundle(sourceFiles), emitOnlyDtsFiles);
|
||||
const bundle = createBundle(sourceFiles);
|
||||
const result = action(getOutputPathsFor(bundle, host, emitOnlyDtsFiles), bundle);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@@ -37,10 +34,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
for (const sourceFile of sourceFiles) {
|
||||
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
|
||||
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
|
||||
const declarationFilePath = !isSourceFileJavaScript(sourceFile) && (emitOnlyDtsFiles || options.declaration) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
|
||||
const result = action({ jsFilePath, sourceMapFilePath, declarationFilePath }, sourceFile, emitOnlyDtsFiles);
|
||||
const result = action(getOutputPathsFor(sourceFile, host, emitOnlyDtsFiles), sourceFile);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@@ -48,6 +42,25 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export function getOutputPathsFor(sourceFile: SourceFile | Bundle, host: EmitHost, forceDtsPaths: boolean) {
|
||||
const options = host.getCompilerOptions();
|
||||
if (sourceFile.kind === SyntaxKind.Bundle) {
|
||||
const jsFilePath = options.outFile || options.out;
|
||||
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
|
||||
const declarationFilePath = (forceDtsPaths || options.declaration) ? removeFileExtension(jsFilePath) + Extension.Dts : undefined;
|
||||
return { jsFilePath, sourceMapFilePath, declarationFilePath };
|
||||
}
|
||||
else {
|
||||
const jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, getOutputExtension(sourceFile, options));
|
||||
const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options);
|
||||
// For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error
|
||||
const isJs = isSourceFileJavaScript(sourceFile);
|
||||
const declarationFilePath = ((forceDtsPaths || options.declaration) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile, host) : undefined;
|
||||
return { jsFilePath, sourceMapFilePath, declarationFilePath };
|
||||
}
|
||||
}
|
||||
|
||||
function getSourceMapFilePath(jsFilePath: string, options: CompilerOptions) {
|
||||
return options.sourceMap ? jsFilePath + ".map" : undefined;
|
||||
}
|
||||
@@ -70,13 +83,6 @@ namespace ts {
|
||||
return Extension.Js;
|
||||
}
|
||||
|
||||
function getOriginalSourceFileOrBundle(sourceFileOrBundle: SourceFile | Bundle) {
|
||||
if (sourceFileOrBundle.kind === SyntaxKind.Bundle) {
|
||||
return updateBundle(sourceFileOrBundle, sameMap(sourceFileOrBundle.sourceFiles, getOriginalSourceFile));
|
||||
}
|
||||
return getOriginalSourceFile(sourceFileOrBundle);
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
// targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature
|
||||
export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile, emitOnlyDtsFiles?: boolean, transformers?: TransformerFactory<SourceFile>[]): EmitResult {
|
||||
@@ -94,37 +100,11 @@ namespace ts {
|
||||
let isOwnFileEmit: boolean;
|
||||
let emitSkipped = false;
|
||||
|
||||
const sourceFiles = getSourceFilesToEmit(host, targetSourceFile);
|
||||
|
||||
// Transform the source files
|
||||
const transform = transformNodes(resolver, host, compilerOptions, sourceFiles, transformers, /*allowDtsFiles*/ false);
|
||||
|
||||
// Create a printer to print the nodes
|
||||
const printer = createPrinter(compilerOptions, {
|
||||
// resolver hooks
|
||||
hasGlobalName: resolver.hasGlobalName,
|
||||
|
||||
// transform hooks
|
||||
onEmitNode: transform.emitNodeWithNotification,
|
||||
substituteNode: transform.substituteNode,
|
||||
|
||||
// sourcemap hooks
|
||||
onEmitSourceMapOfNode: sourceMap.emitNodeWithSourceMap,
|
||||
onEmitSourceMapOfToken: sourceMap.emitTokenWithSourceMap,
|
||||
onEmitSourceMapOfPosition: sourceMap.emitPos,
|
||||
|
||||
// emitter hooks
|
||||
onEmitHelpers: emitHelpers,
|
||||
onSetSourceFile: setSourceFile,
|
||||
});
|
||||
|
||||
// Emit each output file
|
||||
performance.mark("beforePrint");
|
||||
forEachEmittedFile(host, emitSourceFileOrBundle, transform.transformed, emitOnlyDtsFiles);
|
||||
forEachEmittedFile(host, emitSourceFileOrBundle, getSourceFilesToEmit(host, targetSourceFile), emitOnlyDtsFiles);
|
||||
performance.measure("printTime", "beforePrint");
|
||||
|
||||
// Clean up emit nodes on parse tree
|
||||
transform.dispose();
|
||||
|
||||
return {
|
||||
emitSkipped,
|
||||
@@ -134,19 +114,8 @@ namespace ts {
|
||||
};
|
||||
|
||||
function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) {
|
||||
// Make sure not to write js file and source map file if any of them cannot be written
|
||||
if (!host.isEmitBlocked(jsFilePath) && !compilerOptions.noEmit && !compilerOptions.emitDeclarationOnly) {
|
||||
if (!emitOnlyDtsFiles) {
|
||||
printSourceFileOrBundle(jsFilePath, sourceMapFilePath, sourceFileOrBundle);
|
||||
}
|
||||
}
|
||||
else {
|
||||
emitSkipped = true;
|
||||
}
|
||||
|
||||
if (declarationFilePath) {
|
||||
emitSkipped = writeDeclarationFile(declarationFilePath, getOriginalSourceFileOrBundle(sourceFileOrBundle), host, resolver, emitterDiagnostics, emitOnlyDtsFiles) || emitSkipped;
|
||||
}
|
||||
emitJsFileOrBundle(sourceFileOrBundle, jsFilePath, sourceMapFilePath);
|
||||
emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath);
|
||||
|
||||
if (!emitSkipped && emittedFilesList) {
|
||||
if (!emitOnlyDtsFiles) {
|
||||
@@ -161,7 +130,77 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function printSourceFileOrBundle(jsFilePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle) {
|
||||
function emitJsFileOrBundle(sourceFileOrBundle: SourceFile | Bundle, jsFilePath: string, sourceMapFilePath: string) {
|
||||
const sourceFiles = isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles;
|
||||
// Make sure not to write js file and source map file if any of them cannot be written
|
||||
if (host.isEmitBlocked(jsFilePath) || compilerOptions.noEmit || compilerOptions.emitDeclarationOnly) {
|
||||
emitSkipped = true;
|
||||
return;
|
||||
}
|
||||
if (emitOnlyDtsFiles) {
|
||||
return;
|
||||
}
|
||||
// Transform the source files
|
||||
const transform = transformNodes(resolver, host, compilerOptions, sourceFiles, transformers, /*allowDtsFiles*/ false);
|
||||
|
||||
// Create a printer to print the nodes
|
||||
const printer = createPrinter(compilerOptions, {
|
||||
// resolver hooks
|
||||
hasGlobalName: resolver.hasGlobalName,
|
||||
|
||||
// transform hooks
|
||||
onEmitNode: transform.emitNodeWithNotification,
|
||||
substituteNode: transform.substituteNode,
|
||||
|
||||
// sourcemap hooks
|
||||
onEmitSourceMapOfNode: sourceMap.emitNodeWithSourceMap,
|
||||
onEmitSourceMapOfToken: sourceMap.emitTokenWithSourceMap,
|
||||
onEmitSourceMapOfPosition: sourceMap.emitPos,
|
||||
|
||||
// emitter hooks
|
||||
onEmitHelpers: emitHelpers,
|
||||
onSetSourceFile: setSourceFile,
|
||||
});
|
||||
|
||||
printSourceFileOrBundle(jsFilePath, sourceMapFilePath, isSourceFile(sourceFileOrBundle) ? transform.transformed[0] : createBundle(transform.transformed), printer);
|
||||
|
||||
// Clean up emit nodes on parse tree
|
||||
transform.dispose();
|
||||
}
|
||||
|
||||
function emitDeclarationFileOrBundle(sourceFileOrBundle: SourceFile | Bundle, declarationFilePath: string | undefined) {
|
||||
if (!(declarationFilePath && !isInJavaScriptFile(sourceFileOrBundle))) {
|
||||
return;
|
||||
}
|
||||
const sourceFiles = isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles;
|
||||
// Setup and perform the transformation to retrieve declarations from the input files
|
||||
const nonJsFiles = filter(sourceFiles, isSourceFileNotJavaScript);
|
||||
const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles)] : nonJsFiles;
|
||||
const declarationTransform = transformNodes(resolver, host, compilerOptions, inputListOrBundle, [transformDeclarations], /*allowDtsFiles*/ false);
|
||||
if (length(declarationTransform.diagnostics)) {
|
||||
for (const diagnostic of declarationTransform.diagnostics) {
|
||||
emitterDiagnostics.add(diagnostic);
|
||||
}
|
||||
}
|
||||
const declarationPrinter = createPrinter({ ...compilerOptions, onlyPrintJsDocStyle: true } as PrinterOptions, {
|
||||
// resolver hooks
|
||||
hasGlobalName: resolver.hasGlobalName,
|
||||
|
||||
// transform hooks
|
||||
onEmitNode: declarationTransform.emitNodeWithNotification,
|
||||
substituteNode: declarationTransform.substituteNode,
|
||||
});
|
||||
const declBlocked = (!!declarationTransform.diagnostics && !!declarationTransform.diagnostics.length) || !!host.isEmitBlocked(declarationFilePath) || !!compilerOptions.noEmit;
|
||||
emitSkipped = emitSkipped || declBlocked;
|
||||
if (!declBlocked || emitOnlyDtsFiles) {
|
||||
const previousState = sourceMap.setState(/*disabled*/ true);
|
||||
printSourceFileOrBundle(declarationFilePath, /*sourceMapFilePath*/ undefined, declarationTransform.transformed[0], declarationPrinter, /*shouldSkipSourcemap*/ true);
|
||||
sourceMap.setState(previousState);
|
||||
}
|
||||
declarationTransform.dispose();
|
||||
}
|
||||
|
||||
function printSourceFileOrBundle(jsFilePath: string, sourceMapFilePath: string, sourceFileOrBundle: SourceFile | Bundle, printer: Printer, shouldSkipSourcemap = false) {
|
||||
const bundle = sourceFileOrBundle.kind === SyntaxKind.Bundle ? sourceFileOrBundle : undefined;
|
||||
const sourceFile = sourceFileOrBundle.kind === SyntaxKind.SourceFile ? sourceFileOrBundle : undefined;
|
||||
const sourceFiles = bundle ? bundle.sourceFiles : [sourceFile];
|
||||
@@ -180,17 +219,17 @@ namespace ts {
|
||||
writer.writeLine();
|
||||
|
||||
const sourceMappingURL = sourceMap.getSourceMappingURL();
|
||||
if (sourceMappingURL) {
|
||||
if (!shouldSkipSourcemap && sourceMappingURL) {
|
||||
writer.write(`//# ${"sourceMappingURL"}=${sourceMappingURL}`); // Sometimes tools can sometimes see this line as a source mapping url comment
|
||||
}
|
||||
|
||||
// Write the source map
|
||||
if (compilerOptions.sourceMap && !compilerOptions.inlineSourceMap) {
|
||||
if (!shouldSkipSourcemap && compilerOptions.sourceMap && !compilerOptions.inlineSourceMap) {
|
||||
writeFile(host, emitterDiagnostics, sourceMapFilePath, sourceMap.getText(), /*writeByteOrderMark*/ false, sourceFiles);
|
||||
}
|
||||
|
||||
// Record source map data for the test harness.
|
||||
if (sourceMapDataList) {
|
||||
if (!shouldSkipSourcemap && sourceMapDataList) {
|
||||
sourceMapDataList.push(sourceMap.getSourceMapData());
|
||||
}
|
||||
|
||||
@@ -384,6 +423,7 @@ namespace ts {
|
||||
emitShebangIfNeeded(bundle);
|
||||
emitPrologueDirectivesIfNeeded(bundle);
|
||||
emitHelpersIndirect(bundle);
|
||||
emitSyntheticTripleSlashReferencesIfNeeded(bundle);
|
||||
for (const sourceFile of bundle.sourceFiles) {
|
||||
print(EmitHint.SourceFile, sourceFile, sourceFile);
|
||||
}
|
||||
@@ -2044,6 +2084,7 @@ namespace ts {
|
||||
emit(node.name);
|
||||
|
||||
let body = node.body;
|
||||
if (!body) return writeSemicolon();
|
||||
while (body.kind === SyntaxKind.ModuleDeclaration) {
|
||||
writePunctuation(".");
|
||||
emit((<ModuleDeclaration>body).name);
|
||||
@@ -2418,11 +2459,31 @@ namespace ts {
|
||||
emitSourceFileWorker(node);
|
||||
}
|
||||
|
||||
function emitSyntheticTripleSlashReferencesIfNeeded(node: Bundle) {
|
||||
emitTripleSlashDirectives(node.syntheticFileReferences || [], node.syntheticTypeReferences || []);
|
||||
}
|
||||
|
||||
function emitTripleSlashDirectivesIfNeeded(node: SourceFile) {
|
||||
if (node.isDeclarationFile) emitTripleSlashDirectives(node.referencedFiles, node.typeReferenceDirectives);
|
||||
}
|
||||
|
||||
function emitTripleSlashDirectives(files: ReadonlyArray<FileReference>, types: ReadonlyArray<FileReference>) {
|
||||
for (const directive of files) {
|
||||
write(`/// <reference path="${directive.fileName}" />`);
|
||||
writeLine();
|
||||
}
|
||||
for (const directive of types) {
|
||||
write(`/// <reference types="${directive.fileName}" />`);
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
function emitSourceFileWorker(node: SourceFile) {
|
||||
const statements = node.statements;
|
||||
pushNameGenerationScope(node);
|
||||
emitHelpersIndirect(node);
|
||||
const index = findIndex(statements, statement => !isPrologueDirective(statement));
|
||||
emitTripleSlashDirectivesIfNeeded(node);
|
||||
emitList(node, statements, ListFormat.MultiLine, index === -1 ? statements.length : index);
|
||||
popNameGenerationScope(node);
|
||||
}
|
||||
@@ -2668,7 +2729,7 @@ namespace ts {
|
||||
|
||||
if (format & ListFormat.BracketsMask) {
|
||||
writePunctuation(getOpeningBracket(format));
|
||||
if (isEmpty) {
|
||||
if (isEmpty && !isUndefined) {
|
||||
emitTrailingCommentsOfPosition(children.pos, /*prefixSpace*/ true); // Emit comments within empty bracketed lists
|
||||
}
|
||||
}
|
||||
@@ -2796,7 +2857,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (format & ListFormat.BracketsMask) {
|
||||
if (isEmpty) {
|
||||
if (isEmpty && !isUndefined) {
|
||||
emitLeadingCommentsOfPosition(children.end); // Emit leading comments within empty lists
|
||||
}
|
||||
writePunctuation(getClosingBracket(format));
|
||||
@@ -2927,21 +2988,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function guessIndentation(lines: string[]) {
|
||||
let indentation: number;
|
||||
for (const line of lines) {
|
||||
for (let i = 0; i < line.length && (indentation === undefined || i < indentation); i++) {
|
||||
if (!isWhiteSpaceLike(line.charCodeAt(i))) {
|
||||
if (indentation === undefined || i < indentation) {
|
||||
indentation = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return indentation;
|
||||
}
|
||||
|
||||
function increaseIndentIf(value: boolean, valueToWriteWhenNotIndenting?: string) {
|
||||
if (value) {
|
||||
increaseIndent();
|
||||
@@ -3239,8 +3285,15 @@ namespace ts {
|
||||
* in global scope. The name is formed by adding an '_n' suffix to the specified base name,
|
||||
* where n is a positive integer. Note that names generated by makeTempVariableName and
|
||||
* makeUniqueName are guaranteed to never conflict.
|
||||
* If `optimistic` is set, the first instance will use 'baseName' verbatim instead of 'baseName_1'
|
||||
*/
|
||||
function makeUniqueName(baseName: string): string {
|
||||
function makeUniqueName(baseName: string, optimistic?: boolean): string {
|
||||
if (optimistic) {
|
||||
if (isUniqueName(baseName)) {
|
||||
generatedNames.set(baseName, true);
|
||||
return baseName;
|
||||
}
|
||||
}
|
||||
// Find the first unique 'name_n', where n is a positive number
|
||||
if (baseName.charCodeAt(baseName.length - 1) !== CharacterCodes._) {
|
||||
baseName += "_";
|
||||
@@ -3335,6 +3388,8 @@ namespace ts {
|
||||
return makeTempVariableName(TempFlags._i, !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes));
|
||||
case GeneratedIdentifierFlags.Unique:
|
||||
return makeUniqueName(idText(name));
|
||||
case GeneratedIdentifierFlags.OptimisticUnique:
|
||||
return makeUniqueName(idText(name), /*optimistic*/ true);
|
||||
}
|
||||
|
||||
Debug.fail("Unsupported GeneratedIdentifierKind.");
|
||||
|
||||
+45
-10
@@ -171,6 +171,15 @@ namespace ts {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Create a unique name based on the supplied text. */
|
||||
export function createOptimisticUniqueName(text: string): Identifier {
|
||||
const name = createIdentifier(text);
|
||||
name.autoGenerateFlags = GeneratedIdentifierFlags.OptimisticUnique;
|
||||
name.autoGenerateId = nextAutoGenerateId;
|
||||
nextAutoGenerateId++;
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Create a unique name generated for a node. */
|
||||
export function getGeneratedNameForNode(node: Node): Identifier;
|
||||
/* @internal */ export function getGeneratedNameForNode(node: Node, shouldSkipNameGenerationScope?: boolean): Identifier; // tslint:disable-line unified-signatures
|
||||
@@ -214,6 +223,28 @@ namespace ts {
|
||||
return <BooleanLiteral & Token<SyntaxKind.FalseKeyword>>createSynthesizedNode(SyntaxKind.FalseKeyword);
|
||||
}
|
||||
|
||||
// Modifiers
|
||||
|
||||
export function createModifier<T extends Modifier["kind"]>(kind: T) {
|
||||
return createToken(kind);
|
||||
}
|
||||
|
||||
export function createModifiersFromModifierFlags(flags: ModifierFlags) {
|
||||
const result: Modifier[] = [];
|
||||
if (flags & ModifierFlags.Export) { result.push(createModifier(SyntaxKind.ExportKeyword)); }
|
||||
if (flags & ModifierFlags.Ambient) { result.push(createModifier(SyntaxKind.DeclareKeyword)); }
|
||||
if (flags & ModifierFlags.Default) { result.push(createModifier(SyntaxKind.DefaultKeyword)); }
|
||||
if (flags & ModifierFlags.Const) { result.push(createModifier(SyntaxKind.ConstKeyword)); }
|
||||
if (flags & ModifierFlags.Public) { result.push(createModifier(SyntaxKind.PublicKeyword)); }
|
||||
if (flags & ModifierFlags.Private) { result.push(createModifier(SyntaxKind.PrivateKeyword)); }
|
||||
if (flags & ModifierFlags.Protected) { result.push(createModifier(SyntaxKind.ProtectedKeyword)); }
|
||||
if (flags & ModifierFlags.Abstract) { result.push(createModifier(SyntaxKind.AbstractKeyword)); }
|
||||
if (flags & ModifierFlags.Static) { result.push(createModifier(SyntaxKind.StaticKeyword)); }
|
||||
if (flags & ModifierFlags.Readonly) { result.push(createModifier(SyntaxKind.ReadonlyKeyword)); }
|
||||
if (flags & ModifierFlags.Async) { result.push(createModifier(SyntaxKind.AsyncKeyword)); }
|
||||
return result;
|
||||
}
|
||||
|
||||
// Names
|
||||
|
||||
export function createQualifiedName(left: EntityName, right: string | Identifier) {
|
||||
@@ -2349,8 +2380,13 @@ namespace ts {
|
||||
|
||||
// Top-level nodes
|
||||
|
||||
export function updateSourceFileNode(node: SourceFile, statements: ReadonlyArray<Statement>) {
|
||||
if (node.statements !== statements) {
|
||||
export function updateSourceFileNode(node: SourceFile, statements: ReadonlyArray<Statement>, isDeclarationFile?: boolean, referencedFiles?: SourceFile["referencedFiles"], typeReferences?: SourceFile["typeReferenceDirectives"]) {
|
||||
if (
|
||||
node.statements !== statements ||
|
||||
(isDeclarationFile !== undefined && node.isDeclarationFile !== isDeclarationFile) ||
|
||||
(referencedFiles !== undefined && node.referencedFiles !== referencedFiles) ||
|
||||
(typeReferences !== undefined && node.typeReferenceDirectives !== typeReferences)
|
||||
) {
|
||||
const updated = <SourceFile>createSynthesizedNode(SyntaxKind.SourceFile);
|
||||
updated.flags |= node.flags;
|
||||
updated.statements = createNodeArray(statements);
|
||||
@@ -2358,12 +2394,12 @@ namespace ts {
|
||||
updated.fileName = node.fileName;
|
||||
updated.path = node.path;
|
||||
updated.text = node.text;
|
||||
updated.isDeclarationFile = isDeclarationFile === undefined ? node.isDeclarationFile : isDeclarationFile;
|
||||
updated.referencedFiles = referencedFiles === undefined ? node.referencedFiles : referencedFiles;
|
||||
updated.typeReferenceDirectives = typeReferences === undefined ? node.typeReferenceDirectives : typeReferences;
|
||||
if (node.amdDependencies !== undefined) updated.amdDependencies = node.amdDependencies;
|
||||
if (node.moduleName !== undefined) updated.moduleName = node.moduleName;
|
||||
if (node.referencedFiles !== undefined) updated.referencedFiles = node.referencedFiles;
|
||||
if (node.typeReferenceDirectives !== undefined) updated.typeReferenceDirectives = node.typeReferenceDirectives;
|
||||
if (node.languageVariant !== undefined) updated.languageVariant = node.languageVariant;
|
||||
if (node.isDeclarationFile !== undefined) updated.isDeclarationFile = node.isDeclarationFile;
|
||||
if (node.renamedDependencies !== undefined) updated.renamedDependencies = node.renamedDependencies;
|
||||
if (node.hasNoDefaultLib !== undefined) updated.hasNoDefaultLib = node.hasNoDefaultLib;
|
||||
if (node.languageVersion !== undefined) updated.languageVersion = node.languageVersion;
|
||||
@@ -2958,7 +2994,8 @@ namespace ts {
|
||||
requestEmitHelper: noop,
|
||||
resumeLexicalEnvironment: noop,
|
||||
startLexicalEnvironment: noop,
|
||||
suspendLexicalEnvironment: noop
|
||||
suspendLexicalEnvironment: noop,
|
||||
addDiagnostic: noop,
|
||||
};
|
||||
|
||||
// Compound nodes
|
||||
@@ -3157,8 +3194,7 @@ namespace ts {
|
||||
return { value: o && o[i++], done: !o };
|
||||
}
|
||||
};
|
||||
};
|
||||
`
|
||||
};`
|
||||
};
|
||||
|
||||
export function createValuesHelper(context: TransformationContext, expression: Expression, location?: TextRange) {
|
||||
@@ -3192,8 +3228,7 @@ namespace ts {
|
||||
finally { if (e) throw e.error; }
|
||||
}
|
||||
return ar;
|
||||
};
|
||||
`
|
||||
};`
|
||||
};
|
||||
|
||||
export function createReadHelper(context: TransformationContext, iteratorRecord: Expression, count: number | undefined, location?: TextRange) {
|
||||
|
||||
@@ -52,6 +52,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export function isJSDocLikeText(text: string, start: number) {
|
||||
return text.charCodeAt(start + 1) === CharacterCodes.asterisk &&
|
||||
text.charCodeAt(start + 2) === CharacterCodes.asterisk &&
|
||||
text.charCodeAt(start + 3) !== CharacterCodes.slash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes
|
||||
* stored in properties. If a 'cbNodes' callback is specified, it is invoked for embedded arrays; otherwise,
|
||||
@@ -6219,7 +6226,7 @@ namespace ts {
|
||||
let result: JSDoc;
|
||||
|
||||
// Check for /** (JSDoc opening part)
|
||||
if (!isJsDocStart(content, start)) {
|
||||
if (!isJSDocLikeText(content, start)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -6331,13 +6338,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function isJsDocStart(content: string, start: number) {
|
||||
return content.charCodeAt(start) === CharacterCodes.slash &&
|
||||
content.charCodeAt(start + 1) === CharacterCodes.asterisk &&
|
||||
content.charCodeAt(start + 2) === CharacterCodes.asterisk &&
|
||||
content.charCodeAt(start + 3) !== CharacterCodes.asterisk;
|
||||
}
|
||||
|
||||
function createJSDocComment(): JSDoc {
|
||||
const result = <JSDoc>createNode(SyntaxKind.JSDocComment, start);
|
||||
result.tags = tags && createNodeArray(tags, tagsPos, tagsEnd);
|
||||
|
||||
@@ -67,6 +67,11 @@ namespace ts {
|
||||
* Gets test data for source maps.
|
||||
*/
|
||||
getSourceMapData(): SourceMapData;
|
||||
|
||||
/**
|
||||
* @returns the previous disabled state
|
||||
*/
|
||||
setState(disabled: boolean): boolean;
|
||||
}
|
||||
|
||||
// Used for initialize lastEncodedSourceMapSpan and reset lastEncodedSourceMapSpan when updateLastEncodedAndRecordedSpans
|
||||
@@ -107,8 +112,15 @@ namespace ts {
|
||||
emitTokenWithSourceMap,
|
||||
getText,
|
||||
getSourceMappingURL,
|
||||
setState,
|
||||
};
|
||||
|
||||
function setState(state: boolean) {
|
||||
const last = disabled;
|
||||
disabled = state;
|
||||
return last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips trivia such as comments and white-space that can optionally overriden by the source map source
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
/// <reference path="transformers/module/module.ts" />
|
||||
/// <reference path="transformers/module/system.ts" />
|
||||
/// <reference path="transformers/module/es2015.ts" />
|
||||
/// <reference path="transformers/declarations.ts" />
|
||||
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
@@ -104,6 +105,7 @@ namespace ts {
|
||||
let onSubstituteNode: TransformationContext["onSubstituteNode"] = (_, node) => node;
|
||||
let onEmitNode: TransformationContext["onEmitNode"] = (hint, node, callback) => callback(hint, node);
|
||||
let state = TransformationState.Uninitialized;
|
||||
const diagnostics: Diagnostic[] = [];
|
||||
|
||||
// The transformation context is provided to each transformer as part of transformer
|
||||
// initialization.
|
||||
@@ -134,6 +136,9 @@ namespace ts {
|
||||
Debug.assert(state < TransformationState.Initialized, "Cannot modify transformation hooks after initialization has completed.");
|
||||
Debug.assert(value !== undefined, "Value must not be 'undefined'");
|
||||
onEmitNode = value;
|
||||
},
|
||||
addDiagnostic(diag) {
|
||||
diagnostics.push(diag);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -163,7 +168,8 @@ namespace ts {
|
||||
transformed,
|
||||
substituteNode,
|
||||
emitNodeWithNotification,
|
||||
dispose
|
||||
dispose,
|
||||
diagnostics
|
||||
};
|
||||
|
||||
function transformRoot(node: T) {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,469 @@
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
export type GetSymbolAccessibilityDiagnostic = (symbolAccessibilityResult: SymbolAccessibilityResult) => (SymbolAccessibilityDiagnostic | undefined);
|
||||
|
||||
export interface SymbolAccessibilityDiagnostic {
|
||||
errorNode: Node;
|
||||
diagnosticMessage: DiagnosticMessage;
|
||||
typeName?: DeclarationName | QualifiedName;
|
||||
}
|
||||
|
||||
export type DeclarationDiagnosticProducing =
|
||||
| VariableDeclaration
|
||||
| PropertyDeclaration
|
||||
| PropertySignature
|
||||
| BindingElement
|
||||
| SetAccessorDeclaration
|
||||
| GetAccessorDeclaration
|
||||
| ConstructSignatureDeclaration
|
||||
| CallSignatureDeclaration
|
||||
| MethodDeclaration
|
||||
| MethodSignature
|
||||
| FunctionDeclaration
|
||||
| ParameterDeclaration
|
||||
| TypeParameterDeclaration
|
||||
| ExpressionWithTypeArguments
|
||||
| ImportEqualsDeclaration
|
||||
| TypeAliasDeclaration
|
||||
| ConstructorDeclaration
|
||||
| IndexSignatureDeclaration;
|
||||
|
||||
export function canProduceDiagnostics(node: Node): node is DeclarationDiagnosticProducing {
|
||||
return isVariableDeclaration(node) ||
|
||||
isPropertyDeclaration(node) ||
|
||||
isPropertySignature(node) ||
|
||||
isBindingElement(node) ||
|
||||
isSetAccessor(node) ||
|
||||
isGetAccessor(node) ||
|
||||
isConstructSignatureDeclaration(node) ||
|
||||
isCallSignatureDeclaration(node) ||
|
||||
isMethodDeclaration(node) ||
|
||||
isMethodSignature(node) ||
|
||||
isFunctionDeclaration(node) ||
|
||||
isParameter(node) ||
|
||||
isTypeParameterDeclaration(node) ||
|
||||
isExpressionWithTypeArguments(node) ||
|
||||
isImportEqualsDeclaration(node) ||
|
||||
isTypeAliasDeclaration(node) ||
|
||||
isConstructorDeclaration(node) ||
|
||||
isIndexSignatureDeclaration(node);
|
||||
}
|
||||
|
||||
export function createGetSymbolAccessibilityDiagnosticForNodeName(node: DeclarationDiagnosticProducing) {
|
||||
if (isSetAccessor(node) || isGetAccessor(node)) {
|
||||
return getAccessorNameVisibilityError;
|
||||
}
|
||||
else if (isMethodSignature(node) || isMethodDeclaration(node)) {
|
||||
return getMethodNameVisibilityError;
|
||||
}
|
||||
else {
|
||||
return createGetSymbolAccessibilityDiagnosticForNode(node);
|
||||
}
|
||||
function getAccessorNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult) {
|
||||
const diagnosticMessage = getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult);
|
||||
return diagnosticMessage !== undefined ? {
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
typeName: (node as NamedDeclaration).name
|
||||
} : undefined;
|
||||
}
|
||||
|
||||
function getAccessorNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
|
||||
if (hasModifier(node, ModifierFlags.Static)) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
|
||||
}
|
||||
}
|
||||
|
||||
function getMethodNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
|
||||
const diagnosticMessage = getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult);
|
||||
return diagnosticMessage !== undefined ? {
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
typeName: (node as NamedDeclaration).name
|
||||
} : undefined;
|
||||
}
|
||||
|
||||
function getMethodNameVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
|
||||
if (hasModifier(node, ModifierFlags.Static)) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Public_static_method_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Public_method_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Public_method_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Public_method_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Method_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Method_0_of_exported_interface_has_or_is_using_private_name_1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationDiagnosticProducing) {
|
||||
if (isVariableDeclaration(node) || isPropertyDeclaration(node) || isPropertySignature(node) || isBindingElement(node) || isConstructorDeclaration(node)) {
|
||||
return getVariableDeclarationTypeVisibilityError;
|
||||
}
|
||||
else if (isSetAccessor(node) || isGetAccessor(node)) {
|
||||
return getAccessorDeclarationTypeVisibilityError;
|
||||
}
|
||||
else if (isConstructSignatureDeclaration(node) || isCallSignatureDeclaration(node) || isMethodDeclaration(node) || isMethodSignature(node) || isFunctionDeclaration(node) || isIndexSignatureDeclaration(node)) {
|
||||
return getReturnTypeVisibilityError;
|
||||
}
|
||||
else if (isParameter(node)) {
|
||||
if (isParameterPropertyDeclaration(node) && hasModifier(node.parent, ModifierFlags.Private)) {
|
||||
return getVariableDeclarationTypeVisibilityError;
|
||||
}
|
||||
return getParameterDeclarationTypeVisibilityError;
|
||||
}
|
||||
else if (isTypeParameterDeclaration(node)) {
|
||||
return getTypeParameterConstraintVisibilityError;
|
||||
}
|
||||
else if (isExpressionWithTypeArguments(node)) {
|
||||
return getHeritageClauseVisibilityError;
|
||||
}
|
||||
else if (isImportEqualsDeclaration(node)) {
|
||||
return getImportEntityNameVisibilityError;
|
||||
}
|
||||
else if (isTypeAliasDeclaration(node)) {
|
||||
return getTypeAliasDeclarationVisibilityError;
|
||||
}
|
||||
else {
|
||||
Debug.assertNever(node, `Attempted to set a declaration diagnostic context for unhandled node kind: ${(ts as any).SyntaxKind[(node as any).kind]}`);
|
||||
}
|
||||
|
||||
function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
|
||||
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
|
||||
}
|
||||
// This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit
|
||||
// The only exception here is if the constructor was marked as private. we are not emitting the constructor parameters at all.
|
||||
else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature ||
|
||||
(node.kind === SyntaxKind.Parameter && hasModifier(node.parent, ModifierFlags.Private))) {
|
||||
// TODO(jfreeman): Deal with computed properties in error reporting.
|
||||
if (hasModifier(node, ModifierFlags.Static)) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else if (node.parent.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.Parameter) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
// Interfaces cannot have types that cannot be named
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getVariableDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
|
||||
const diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult);
|
||||
return diagnosticMessage !== undefined ? {
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
typeName: (node as NamedDeclaration).name
|
||||
} : undefined;
|
||||
}
|
||||
|
||||
function getAccessorDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
|
||||
let diagnosticMessage: DiagnosticMessage;
|
||||
if (node.kind === SyntaxKind.SetAccessor) {
|
||||
// Getters can infer the return type from the returned expression, but setters cannot, so the
|
||||
// "_from_external_module_1_but_cannot_be_named" case cannot occur.
|
||||
if (hasModifier(node, ModifierFlags.Static)) {
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_type_of_public_static_setter_0_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Parameter_type_of_public_setter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_type_of_public_setter_0_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hasModifier(node, ModifierFlags.Static)) {
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Return_type_of_public_static_getter_0_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Return_type_of_public_getter_0_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Return_type_of_public_getter_0_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Return_type_of_public_getter_0_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
}
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: (node as NamedDeclaration).name,
|
||||
typeName: (node as NamedDeclaration).name
|
||||
};
|
||||
}
|
||||
|
||||
function getReturnTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
|
||||
let diagnosticMessage: DiagnosticMessage;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ConstructSignature:
|
||||
// Interfaces cannot have return types that cannot be named
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
|
||||
Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
|
||||
break;
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
// Interfaces cannot have return types that cannot be named
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
|
||||
Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
|
||||
break;
|
||||
|
||||
case SyntaxKind.IndexSignature:
|
||||
// Interfaces cannot have return types that cannot be named
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
|
||||
Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
|
||||
break;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
if (hasModifier(node, ModifierFlags.Static)) {
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
|
||||
Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
|
||||
Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
|
||||
}
|
||||
else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
|
||||
Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
|
||||
Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
|
||||
}
|
||||
else {
|
||||
// Interfaces cannot have return types that cannot be named
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
|
||||
Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
diagnosticMessage = symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
|
||||
Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 :
|
||||
Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.fail("This is unknown kind for signature: " + node.kind);
|
||||
}
|
||||
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: (node as NamedDeclaration).name || node
|
||||
};
|
||||
}
|
||||
|
||||
function getParameterDeclarationTypeVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
|
||||
const diagnosticMessage: DiagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult);
|
||||
return diagnosticMessage !== undefined ? {
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
typeName: (node as NamedDeclaration).name
|
||||
} : undefined;
|
||||
}
|
||||
|
||||
function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult): DiagnosticMessage {
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
|
||||
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.ConstructorType:
|
||||
// Interfaces cannot have parameter types that cannot be named
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
// Interfaces cannot have parameter types that cannot be named
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
|
||||
case SyntaxKind.IndexSignature:
|
||||
// Interfaces cannot have parameter types that cannot be named
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
if (hasModifier(node.parent, ModifierFlags.Static)) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
// Interfaces cannot have parameter types that cannot be named
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
|
||||
}
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionType:
|
||||
return symbolAccessibilityResult.errorModuleName ?
|
||||
symbolAccessibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
|
||||
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
|
||||
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
|
||||
Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
|
||||
|
||||
default:
|
||||
Debug.fail(`Unknown parent for parameter: ${(ts as any).SyntaxKind[node.parent.kind]}`);
|
||||
}
|
||||
}
|
||||
|
||||
function getTypeParameterConstraintVisibilityError(): SymbolAccessibilityDiagnostic {
|
||||
// Type parameter constraints are named by user so we should always be able to name it
|
||||
let diagnosticMessage: DiagnosticMessage;
|
||||
switch (node.parent.kind) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.ConstructSignature:
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
if (hasModifier(node.parent, ModifierFlags.Static)) {
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_type_alias_has_or_is_using_private_name_1;
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
|
||||
}
|
||||
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
typeName: (node as NamedDeclaration).name
|
||||
};
|
||||
}
|
||||
|
||||
function getHeritageClauseVisibilityError(): SymbolAccessibilityDiagnostic {
|
||||
let diagnosticMessage: DiagnosticMessage;
|
||||
// Heritage clause is written by user so it can always be named
|
||||
if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
// Class or Interface implemented/extended is inaccessible
|
||||
diagnosticMessage = (node as ExpressionWithTypeArguments).parent.token === SyntaxKind.ImplementsKeyword ?
|
||||
Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
|
||||
Diagnostics.extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
|
||||
}
|
||||
else {
|
||||
// interface is inaccessible
|
||||
diagnosticMessage = Diagnostics.extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
|
||||
}
|
||||
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: node,
|
||||
typeName: getNameOfDeclaration((node as ExpressionWithTypeArguments).parent.parent)
|
||||
};
|
||||
}
|
||||
|
||||
function getImportEntityNameVisibilityError(): SymbolAccessibilityDiagnostic {
|
||||
return {
|
||||
diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1,
|
||||
errorNode: node,
|
||||
typeName: (node as NamedDeclaration).name
|
||||
};
|
||||
}
|
||||
|
||||
function getTypeAliasDeclarationVisibilityError(): SymbolAccessibilityDiagnostic {
|
||||
return {
|
||||
diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
|
||||
errorNode: (node as TypeAliasDeclaration).type,
|
||||
typeName: (node as TypeAliasDeclaration).name
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -669,8 +669,7 @@ namespace ts {
|
||||
name: "typescript:async-super",
|
||||
scoped: true,
|
||||
text: `
|
||||
const _super = name => super[name];
|
||||
`
|
||||
const _super = name => super[name];`
|
||||
};
|
||||
|
||||
export const advancedAsyncSuperHelper: EmitHelper = {
|
||||
@@ -680,7 +679,6 @@ namespace ts {
|
||||
const _super = (function (geti, seti) {
|
||||
const cache = Object.create(null);
|
||||
return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } });
|
||||
})(name => super[name], (name, value) => super[name] = value);
|
||||
`
|
||||
})(name => super[name], (name, value) => super[name] = value);`
|
||||
};
|
||||
}
|
||||
@@ -887,8 +887,7 @@ namespace ts {
|
||||
name: "typescript:await",
|
||||
scoped: false,
|
||||
text: `
|
||||
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
||||
`
|
||||
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }`
|
||||
};
|
||||
|
||||
function createAwaitHelper(context: TransformationContext, expression: Expression) {
|
||||
@@ -910,8 +909,7 @@ namespace ts {
|
||||
function fulfill(value) { resume("next", value); }
|
||||
function reject(value) { resume("throw", value); }
|
||||
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
||||
};
|
||||
`
|
||||
};`
|
||||
};
|
||||
|
||||
function createAsyncGeneratorHelper(context: TransformationContext, generatorFunc: FunctionExpression) {
|
||||
@@ -940,8 +938,7 @@ namespace ts {
|
||||
var i, p;
|
||||
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
||||
function verb(n, f) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; }; }
|
||||
};
|
||||
`
|
||||
};`
|
||||
};
|
||||
|
||||
function createAsyncDelegatorHelper(context: TransformationContext, expression: Expression, location?: TextRange) {
|
||||
@@ -965,8 +962,7 @@ namespace ts {
|
||||
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
||||
var m = o[Symbol.asyncIterator];
|
||||
return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator]();
|
||||
};
|
||||
`
|
||||
};`
|
||||
};
|
||||
|
||||
function createAsyncValuesHelper(context: TransformationContext, expression: Expression, location?: TextRange) {
|
||||
|
||||
@@ -1698,8 +1698,7 @@ namespace ts {
|
||||
text: `
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
`
|
||||
}`
|
||||
};
|
||||
|
||||
function createExportStarHelper(context: TransformationContext, module: Expression) {
|
||||
|
||||
@@ -31,10 +31,11 @@
|
||||
"transformers/module/module.ts",
|
||||
"transformers/module/system.ts",
|
||||
"transformers/module/es2015.ts",
|
||||
"transformers/declarations/diagnostics.ts",
|
||||
"transformers/declarations.ts",
|
||||
"transformer.ts",
|
||||
"comments.ts",
|
||||
"sourcemap.ts",
|
||||
"declarationEmitter.ts",
|
||||
"emitter.ts",
|
||||
"watchUtilities.ts",
|
||||
"program.ts",
|
||||
|
||||
+18
-11
@@ -536,6 +536,7 @@ namespace ts {
|
||||
|
||||
TypeScriptModifier = Ambient | Public | Private | Protected | Readonly | Abstract | Const,
|
||||
ExportDefault = Export | Default,
|
||||
All = Export | Ambient | Public | Private | Protected | Static | Readonly | Abstract | Async | Default | Const
|
||||
}
|
||||
|
||||
export const enum JsxFlags {
|
||||
@@ -697,6 +698,7 @@ namespace ts {
|
||||
Loop = 2, // Automatically generated identifier with a preference for '_i'.
|
||||
Unique = 3, // Unique name based on the 'text' property.
|
||||
Node = 4, // Unique name based on the node in the 'original' property.
|
||||
OptimisticUnique = 5, // Unique name based on the 'text' property, first instance won't use '_#' if there's no conflict
|
||||
KindMask = 7, // Mask to extract the kind of identifier from its flags.
|
||||
|
||||
// Flags
|
||||
@@ -971,9 +973,9 @@ namespace ts {
|
||||
export type FunctionLikeDeclaration =
|
||||
| FunctionDeclaration
|
||||
| MethodDeclaration
|
||||
| ConstructorDeclaration
|
||||
| GetAccessorDeclaration
|
||||
| SetAccessorDeclaration
|
||||
| ConstructorDeclaration
|
||||
| FunctionExpression
|
||||
| ArrowFunction;
|
||||
/** @deprecated Use SignatureDeclaration */
|
||||
@@ -2581,6 +2583,8 @@ namespace ts {
|
||||
export interface Bundle extends Node {
|
||||
kind: SyntaxKind.Bundle;
|
||||
sourceFiles: ReadonlyArray<SourceFile>;
|
||||
/* @internal */ syntheticFileReferences?: ReadonlyArray<FileReference>;
|
||||
/* @internal */ syntheticTypeReferences?: ReadonlyArray<FileReference>;
|
||||
}
|
||||
|
||||
export interface JsonSourceFile extends SourceFile {
|
||||
@@ -3200,15 +3204,16 @@ namespace ts {
|
||||
isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean;
|
||||
isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean;
|
||||
getNodeCheckFlags(node: Node): NodeCheckFlags;
|
||||
isDeclarationVisible(node: Declaration): boolean;
|
||||
isDeclarationVisible(node: Declaration | AnyImportSyntax): boolean;
|
||||
isLateBound(node: Declaration): node is LateBoundDeclaration;
|
||||
collectLinkedAliases(node: Identifier): Node[];
|
||||
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean | undefined;
|
||||
isImplementationOfOverload(node: FunctionLike): boolean | undefined;
|
||||
isRequiredInitializedParameter(node: ParameterDeclaration): boolean;
|
||||
isOptionalUninitializedParameterProperty(node: ParameterDeclaration): boolean;
|
||||
writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: EmitTextWriter): void;
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: EmitTextWriter): void;
|
||||
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: EmitTextWriter): void;
|
||||
createTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker, addUndefined?: boolean): TypeNode;
|
||||
createReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode;
|
||||
createTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: NodeBuilderFlags, tracker: SymbolTracker): TypeNode;
|
||||
createLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): Expression;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult;
|
||||
isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
|
||||
@@ -3222,7 +3227,6 @@ namespace ts {
|
||||
getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): string[];
|
||||
getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[];
|
||||
isLiteralConstDeclaration(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration): boolean;
|
||||
writeLiteralConstValue(node: VariableDeclaration | PropertyDeclaration | PropertySignature | ParameterDeclaration, writer: EmitTextWriter): void;
|
||||
getJsxFactoryEntity(location?: Node): EntityName;
|
||||
}
|
||||
|
||||
@@ -4862,6 +4866,8 @@ namespace ts {
|
||||
* before returning the `NodeTransformer` callback.
|
||||
*/
|
||||
onEmitNode: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void;
|
||||
|
||||
/* @internal */ addDiagnostic(diag: Diagnostic): void;
|
||||
}
|
||||
|
||||
export interface TransformationResult<T extends Node> {
|
||||
@@ -5005,6 +5011,7 @@ namespace ts {
|
||||
/*@internal*/ sourceMap?: boolean;
|
||||
/*@internal*/ inlineSourceMap?: boolean;
|
||||
/*@internal*/ extendedDiagnostics?: boolean;
|
||||
/*@internal*/ onlyPrintJsDocStyle?: boolean;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
@@ -5119,10 +5126,10 @@ namespace ts {
|
||||
// Precomputed Formats
|
||||
Modifiers = SingleLine | SpaceBetweenSiblings | NoInterveningComments,
|
||||
HeritageClauses = SingleLine | SpaceBetweenSiblings,
|
||||
SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings | Indented,
|
||||
MultiLineTypeLiteralMembers = MultiLine | Indented,
|
||||
SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings,
|
||||
MultiLineTypeLiteralMembers = MultiLine | Indented | OptionalIfEmpty,
|
||||
|
||||
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
|
||||
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
|
||||
ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings | NoSpaceIfEmpty,
|
||||
@@ -5143,7 +5150,7 @@ namespace ts {
|
||||
InterfaceMembers = Indented | MultiLine,
|
||||
EnumMembers = CommaDelimited | Indented | MultiLine,
|
||||
CaseBlockClauses = Indented | MultiLine,
|
||||
NamedImportsOrExportsElements = CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | SingleLine | SpaceBetweenBraces,
|
||||
NamedImportsOrExportsElements = CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | SingleLine | SpaceBetweenBraces | NoSpaceIfEmpty,
|
||||
JsxElementOrFragmentChildren = SingleLine | NoInterveningComments,
|
||||
JsxElementAttributes = SingleLine | SpaceBetweenSiblings | NoInterveningComments,
|
||||
CaseOrDefaultClauseStatements = Indented | MultiLine | NoTrailingNewLine | OptionalIfEmpty,
|
||||
|
||||
@@ -274,9 +274,9 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isPinnedComment(text: string, comment: CommentRange) {
|
||||
return text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk &&
|
||||
text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation;
|
||||
export function isPinnedComment(text: string, start: number) {
|
||||
return text.charCodeAt(start + 1) === CharacterCodes.asterisk &&
|
||||
text.charCodeAt(start + 2) === CharacterCodes.exclamation;
|
||||
}
|
||||
|
||||
export function getTokenPosOfNode(node: Node, sourceFile?: SourceFileLike, includeJsDoc?: boolean): number {
|
||||
@@ -967,6 +967,10 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isVariableLikeOrAccessor(node: Node): node is AccessorDeclaration | VariableLikeDeclaration {
|
||||
return isVariableLike(node) || isAccessor(node);
|
||||
}
|
||||
|
||||
export function isVariableDeclarationInVariableStatement(node: VariableDeclaration) {
|
||||
return node.parent.kind === SyntaxKind.VariableDeclarationList
|
||||
&& node.parent.parent.kind === SyntaxKind.VariableStatement;
|
||||
@@ -1423,6 +1427,10 @@ namespace ts {
|
||||
return isInJavaScriptFile(file);
|
||||
}
|
||||
|
||||
export function isSourceFileNotJavaScript(file: SourceFile): boolean {
|
||||
return !isInJavaScriptFile(file);
|
||||
}
|
||||
|
||||
export function isInJavaScriptFile(node: Node | undefined): boolean {
|
||||
return node && !!(node.flags & NodeFlags.JavaScriptFile);
|
||||
}
|
||||
@@ -3110,7 +3118,7 @@ namespace ts {
|
||||
return currentDetachedCommentInfo;
|
||||
|
||||
function isPinnedCommentLocal(comment: CommentRange) {
|
||||
return isPinnedComment(text, comment);
|
||||
return isPinnedComment(text, comment.pos);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5983,6 +5991,45 @@ namespace ts {
|
||||
return !!(node as HasType).type;
|
||||
}
|
||||
|
||||
/* True if the node could have a type node a `.type` */
|
||||
/* @internal */
|
||||
export function couldHaveType(node: Node): node is HasType {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
case SyntaxKind.TypePredicate:
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
case SyntaxKind.ParenthesizedType:
|
||||
case SyntaxKind.TypeOperator:
|
||||
case SyntaxKind.MappedType:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.AsExpression:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.JSDocTypeExpression:
|
||||
case SyntaxKind.JSDocNullableType:
|
||||
case SyntaxKind.JSDocNonNullableType:
|
||||
case SyntaxKind.JSDocOptionalType:
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
case SyntaxKind.JSDocVariadicType:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** True if has initializer node attached to it. */
|
||||
/* @internal */
|
||||
export function hasInitializer(node: Node): node is HasInitializer {
|
||||
@@ -6015,6 +6062,30 @@ namespace ts {
|
||||
return node.kind === SyntaxKind.TypeReference || node.kind === SyntaxKind.ExpressionWithTypeArguments;
|
||||
}
|
||||
|
||||
const MAX_SMI_X86 = 0x3fff_ffff;
|
||||
/* @internal */
|
||||
export function guessIndentation(lines: string[]) {
|
||||
let indentation = MAX_SMI_X86;
|
||||
for (const line of lines) {
|
||||
if (!line.length) {
|
||||
continue;
|
||||
}
|
||||
let i = 0;
|
||||
for (; i < line.length && i < indentation; i++) {
|
||||
if (!isWhiteSpaceLike(line.charCodeAt(i))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < indentation) {
|
||||
indentation = i;
|
||||
}
|
||||
if (indentation === 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return indentation === MAX_SMI_X86 ? undefined : indentation;
|
||||
}
|
||||
|
||||
export function isStringLiteralLike(node: Node): node is StringLiteralLike {
|
||||
return node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NoSubstitutionTemplateLiteral;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user