From 16ddaf7d7bdd54e86f975eee79b21082178b0e0c Mon Sep 17 00:00:00 2001 From: kingwl Date: Sun, 22 Apr 2018 20:56:23 +0800 Subject: [PATCH 01/11] improve stripInternal with inline comments --- src/compiler/transformers/declarations.ts | 11 +++++---- src/compiler/utilities.ts | 4 ++++ .../declarationEmitWorkWithInlineComments.js | 23 +++++++++++++++++++ ...larationEmitWorkWithInlineComments.symbols | 11 +++++++++ ...eclarationEmitWorkWithInlineComments.types | 11 +++++++++ .../declarationEmitWorkWithInlineComments.ts | 6 +++++ 6 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitWorkWithInlineComments.js create mode 100644 tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols create mode 100644 tests/baselines/reference/declarationEmitWorkWithInlineComments.types create mode 100644 tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 67e4fa31cb249..ce6ebab605051 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -965,7 +965,7 @@ namespace ts { if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; parameterProperties = compact(flatMap(ctor.parameters, param => { - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier)) return; + if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param, /* isInline */true)) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1140,12 +1140,15 @@ namespace ts { return stringContains(comment, "@internal"); } - function shouldStripInternal(node: Node) { + function shouldStripInternal(node: Node, isInline: boolean = false) { if (stripInternal && node) { - const leadingCommentRanges = getLeadingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile); - if (forEach(leadingCommentRanges, hasInternalAnnotation)) { + const commentRanges = isInline + ? getTrailingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile) + : getLeadingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile); + if (forEach(commentRanges, hasInternalAnnotation)) { return true; } + } return false; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c5cb19e876a6f..14f82b2841161 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -758,6 +758,10 @@ namespace ts { return node.kind !== SyntaxKind.JsxText ? getLeadingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; } + export function getTrailingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { + return node.kind !== SyntaxKind.JsxText ? getTrailingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; + } + export function getJSDocCommentRanges(node: Node, text: string) { const commentRanges = (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter || diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.js b/tests/baselines/reference/declarationEmitWorkWithInlineComments.js new file mode 100644 index 0000000000000..edea82c6ae862 --- /dev/null +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.js @@ -0,0 +1,23 @@ +//// [declarationEmitWorkWithInlineComments.ts] +export class Foo { + constructor(/** @internal */ public bar: string) { } + /** @internal */ zoo: string; +} + + +//// [declarationEmitWorkWithInlineComments.js] +"use strict"; +exports.__esModule = true; +var Foo = /** @class */ (function () { + function Foo(/** @internal */ bar) { + this.bar = bar; + } + return Foo; +}()); +exports.Foo = Foo; + + +//// [declarationEmitWorkWithInlineComments.d.ts] +export declare class Foo { + constructor(/** @internal */ bar: string); +} diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols b/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols new file mode 100644 index 0000000000000..9754b44cd2f23 --- /dev/null +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts === +export class Foo { +>Foo : Symbol(Foo, Decl(declarationEmitWorkWithInlineComments.ts, 0, 0)) + + constructor(/** @internal */ public bar: string) { } +>bar : Symbol(Foo.bar, Decl(declarationEmitWorkWithInlineComments.ts, 1, 14)) + + /** @internal */ zoo: string; +>zoo : Symbol(Foo.zoo, Decl(declarationEmitWorkWithInlineComments.ts, 1, 54)) +} + diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.types b/tests/baselines/reference/declarationEmitWorkWithInlineComments.types new file mode 100644 index 0000000000000..7391ec16002b6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts === +export class Foo { +>Foo : Foo + + constructor(/** @internal */ public bar: string) { } +>bar : string + + /** @internal */ zoo: string; +>zoo : string +} + diff --git a/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts b/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts new file mode 100644 index 0000000000000..544ede8dbf5ae --- /dev/null +++ b/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts @@ -0,0 +1,6 @@ +// @declaration: true +// @stripInternal:true +export class Foo { + constructor(/** @internal */ public bar: string) { } + /** @internal */ zoo: string; +} From fc9af60f64d3100e70f5099dcc6876748c93519c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Mon, 23 Apr 2018 13:34:35 +0800 Subject: [PATCH 02/11] fix lint --- src/compiler/transformers/declarations.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index ce6ebab605051..bbdacccaa103f 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -965,7 +965,7 @@ namespace ts { if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; parameterProperties = compact(flatMap(ctor.parameters, param => { - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param, /* isInline */true)) return; + if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param, /* isInline */ true)) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1140,15 +1140,14 @@ namespace ts { return stringContains(comment, "@internal"); } - function shouldStripInternal(node: Node, isInline: boolean = false) { + function shouldStripInternal(node: Node, isInline?: boolean) { if (stripInternal && node) { - const commentRanges = isInline + const commentRanges = isInline ? getTrailingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile) : getLeadingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile); if (forEach(commentRanges, hasInternalAnnotation)) { return true; } - } return false; } From 6c3ce9f77e0c42436e7984851c6e9598ff59d65d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Wed, 25 Apr 2018 14:21:19 +0800 Subject: [PATCH 03/11] stash --- src/compiler/transformers/declarations.ts | 17 +++--- .../declarationEmitWorkWithInlineComments.js | 53 +++++++++++++++++-- ...larationEmitWorkWithInlineComments.symbols | 36 +++++++++++-- ...eclarationEmitWorkWithInlineComments.types | 36 +++++++++++-- .../declarationEmitWorkWithInlineComments.ts | 20 ++++++- 5 files changed, 140 insertions(+), 22 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index bbdacccaa103f..2bde8bfa6e03e 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -965,7 +965,7 @@ namespace ts { if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; parameterProperties = compact(flatMap(ctor.parameters, param => { - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param, /* isInline */ true)) return; + if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1140,13 +1140,16 @@ namespace ts { return stringContains(comment, "@internal"); } - function shouldStripInternal(node: Node, isInline?: boolean) { + function shouldStripInternal(node: Node) { if (stripInternal && node) { - const commentRanges = isInline - ? getTrailingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile) - : getLeadingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile); - if (forEach(commentRanges, hasInternalAnnotation)) { - return true; + node = getParseTreeNode(node); + const leadingCommentRanges = getLeadingCommentRangesOfNode(node, currentSourceFile); + if (leadingCommentRanges && leadingCommentRanges.length) { + return hasInternalAnnotation(last(leadingCommentRanges)); + } + const trailingCommentRanges = getTrailingCommentRangesOfNode(node, currentSourceFile); + if (trailingCommentRanges && trailingCommentRanges.length) { + return hasInternalAnnotation(last(trailingCommentRanges)); } } return false; diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.js b/tests/baselines/reference/declarationEmitWorkWithInlineComments.js index edea82c6ae862..3f762facb78d9 100644 --- a/tests/baselines/reference/declarationEmitWorkWithInlineComments.js +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.js @@ -1,7 +1,22 @@ //// [declarationEmitWorkWithInlineComments.ts] export class Foo { - constructor(/** @internal */ public bar: string) { } - /** @internal */ zoo: string; + constructor( + /** @internal */ + public isInternal1: string, + /** @internal */ public isInternal2: string, /** @internal */ + public isInternal3: string, + // @internal + public isInternal4: string, + // @internal + /** @internal */ + public isInternal5: string, + /* @internal */ public isInternal6: string, /** @internal */ + // next line + public notInternal1: string, + // @internal + /* next line */ + public notInternal2: string + ) { } } @@ -9,8 +24,29 @@ export class Foo { "use strict"; exports.__esModule = true; var Foo = /** @class */ (function () { - function Foo(/** @internal */ bar) { - this.bar = bar; + function Foo( + /** @internal */ + isInternal1, + /** @internal */ isInternal2, /** @internal */ isInternal3, + // @internal + isInternal4, + // @internal + /** @internal */ + isInternal5, + /* @internal */ isInternal6, /** @internal */ + // next line + notInternal1, + // @internal + /* next line */ + notInternal2) { + this.isInternal1 = isInternal1; + this.isInternal2 = isInternal2; + this.isInternal3 = isInternal3; + this.isInternal4 = isInternal4; + this.isInternal5 = isInternal5; + this.isInternal6 = isInternal6; + this.notInternal1 = notInternal1; + this.notInternal2 = notInternal2; } return Foo; }()); @@ -19,5 +55,12 @@ exports.Foo = Foo; //// [declarationEmitWorkWithInlineComments.d.ts] export declare class Foo { - constructor(/** @internal */ bar: string); + notInternal1: string; + notInternal2: string; + constructor( + /** @internal */ + isInternal1: string, + /** @internal */ isInternal2: string, /** @internal */ isInternal3: string, isInternal4: string, + /** @internal */ + isInternal5: string, isInternal6: string, /** @internal */ notInternal1: string, notInternal2: string); } diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols b/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols index 9754b44cd2f23..c541c67fa0c85 100644 --- a/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols @@ -2,10 +2,38 @@ export class Foo { >Foo : Symbol(Foo, Decl(declarationEmitWorkWithInlineComments.ts, 0, 0)) - constructor(/** @internal */ public bar: string) { } ->bar : Symbol(Foo.bar, Decl(declarationEmitWorkWithInlineComments.ts, 1, 14)) + constructor( + /** @internal */ + public isInternal1: string, +>isInternal1 : Symbol(Foo.isInternal1, Decl(declarationEmitWorkWithInlineComments.ts, 1, 14)) - /** @internal */ zoo: string; ->zoo : Symbol(Foo.zoo, Decl(declarationEmitWorkWithInlineComments.ts, 1, 54)) + /** @internal */ public isInternal2: string, /** @internal */ +>isInternal2 : Symbol(Foo.isInternal2, Decl(declarationEmitWorkWithInlineComments.ts, 3, 31)) + + public isInternal3: string, +>isInternal3 : Symbol(Foo.isInternal3, Decl(declarationEmitWorkWithInlineComments.ts, 4, 48)) + + // @internal + public isInternal4: string, +>isInternal4 : Symbol(Foo.isInternal4, Decl(declarationEmitWorkWithInlineComments.ts, 5, 31)) + + // @internal + /** @internal */ + public isInternal5: string, +>isInternal5 : Symbol(Foo.isInternal5, Decl(declarationEmitWorkWithInlineComments.ts, 7, 31)) + + /* @internal */ public isInternal6: string, /** @internal */ +>isInternal6 : Symbol(Foo.isInternal6, Decl(declarationEmitWorkWithInlineComments.ts, 10, 31)) + + // next line + public notInternal1: string, +>notInternal1 : Symbol(Foo.notInternal1, Decl(declarationEmitWorkWithInlineComments.ts, 11, 47)) + + // @internal + /* next line */ + public notInternal2: string +>notInternal2 : Symbol(Foo.notInternal2, Decl(declarationEmitWorkWithInlineComments.ts, 13, 32)) + + ) { } } diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.types b/tests/baselines/reference/declarationEmitWorkWithInlineComments.types index 7391ec16002b6..3744bec8f51b8 100644 --- a/tests/baselines/reference/declarationEmitWorkWithInlineComments.types +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.types @@ -2,10 +2,38 @@ export class Foo { >Foo : Foo - constructor(/** @internal */ public bar: string) { } ->bar : string + constructor( + /** @internal */ + public isInternal1: string, +>isInternal1 : string - /** @internal */ zoo: string; ->zoo : string + /** @internal */ public isInternal2: string, /** @internal */ +>isInternal2 : string + + public isInternal3: string, +>isInternal3 : string + + // @internal + public isInternal4: string, +>isInternal4 : string + + // @internal + /** @internal */ + public isInternal5: string, +>isInternal5 : string + + /* @internal */ public isInternal6: string, /** @internal */ +>isInternal6 : string + + // next line + public notInternal1: string, +>notInternal1 : string + + // @internal + /* next line */ + public notInternal2: string +>notInternal2 : string + + ) { } } diff --git a/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts b/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts index 544ede8dbf5ae..135e08c202527 100644 --- a/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts +++ b/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts @@ -1,6 +1,22 @@ // @declaration: true // @stripInternal:true + export class Foo { - constructor(/** @internal */ public bar: string) { } - /** @internal */ zoo: string; + constructor( + /** @internal */ + public isInternal1: string, + /** @internal */ public isInternal2: string, /** @internal */ + public isInternal3: string, + // @internal + public isInternal4: string, + // @internal + /** @internal */ + public isInternal5: string, + /* @internal */ public isInternal6: string, /** @internal */ + // next line + public notInternal1: string, + // @internal + /* next line */ + public notInternal2: string + ) { } } From 739f12272c9283b44cef4f38e5e9c0dc891db03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Wed, 25 Apr 2018 18:41:31 +0800 Subject: [PATCH 04/11] simptify StripInternal --- src/compiler/scanner.ts | 12 ++++++------ src/compiler/transformers/declarations.ts | 15 ++++----------- src/compiler/utilities.ts | 8 ++------ 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index f2a01d22c2480..64565134f2372 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -626,13 +626,13 @@ namespace ts { * @returns If "reduce" is true, the accumulated value. If "reduce" is false, the first truthy * return value of the callback. */ - function iterateCommentRanges(reduce: boolean, text: string, pos: number, trailing: boolean, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial?: U): U { + function iterateCommentRanges(reduce: boolean, text: string, pos: number, trailing: boolean, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial?: U, inline?: boolean): U { let pendingPos: number; let pendingEnd: number; let pendingKind: CommentKind; let pendingHasTrailingNewLine: boolean; let hasPendingCommentRange = false; - let collecting = trailing || pos === 0; + let collecting = inline || trailing || pos === 0; let accumulator = initial; scan: while (pos >= 0 && pos < text.length) { const ch = text.charCodeAt(pos); @@ -736,8 +736,8 @@ namespace ts { return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ true, cb, state); } - export function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U) { - return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ false, cb, state, initial); + export function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U, inline?: boolean) { + return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ false, cb, state, initial, inline); } export function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U) { @@ -753,8 +753,8 @@ namespace ts { return comments; } - export function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined { - return reduceEachLeadingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined); + export function getLeadingCommentRanges(text: string, pos: number, inline?: boolean): CommentRange[] | undefined { + return reduceEachLeadingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined, inline); } export function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined { diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 2bde8bfa6e03e..2711970cf8e97 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -965,7 +965,7 @@ namespace ts { if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; parameterProperties = compact(flatMap(ctor.parameters, param => { - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return; + if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param, /* inline */ true)) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1140,17 +1140,10 @@ namespace ts { return stringContains(comment, "@internal"); } - function shouldStripInternal(node: Node) { + function shouldStripInternal(node: Node, inline?: boolean) { if (stripInternal && node) { - node = getParseTreeNode(node); - const leadingCommentRanges = getLeadingCommentRangesOfNode(node, currentSourceFile); - if (leadingCommentRanges && leadingCommentRanges.length) { - return hasInternalAnnotation(last(leadingCommentRanges)); - } - const trailingCommentRanges = getTrailingCommentRangesOfNode(node, currentSourceFile); - if (trailingCommentRanges && trailingCommentRanges.length) { - return hasInternalAnnotation(last(trailingCommentRanges)); - } + const leadingCommentRanges = getLeadingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile, inline); + return length(leadingCommentRanges) && hasInternalAnnotation(last(leadingCommentRanges)); } return false; } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 14f82b2841161..07bcff6bf9d23 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -754,12 +754,8 @@ namespace ts { && (node).expression.kind === SyntaxKind.StringLiteral; } - export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { - return node.kind !== SyntaxKind.JsxText ? getLeadingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; - } - - export function getTrailingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { - return node.kind !== SyntaxKind.JsxText ? getTrailingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; + export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile, inline?: boolean) { + return node.kind !== SyntaxKind.JsxText ? getLeadingCommentRanges(sourceFileOfNode.text, node.pos, inline) : undefined; } export function getJSDocCommentRanges(node: Node, text: string) { From 4c9f83508e3dcdf4385cb6541a7eadf4b68abb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Wed, 25 Apr 2018 18:51:43 +0800 Subject: [PATCH 05/11] fix internal type declaration --- src/compiler/emitter.ts | 4 ++-- src/compiler/types.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2b01f2fdda1bc..9dddacdcf10a7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1,7 +1,6 @@ namespace ts { const brackets = createBracketsMap(); - /*@internal*/ /** * Iterates over the source files that are expected to have an emit output. * @@ -11,6 +10,7 @@ namespace ts { * If an array, the full list of source files to emit. * Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit. */ + /*@internal*/ export function forEachEmittedFile( host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) => T, sourceFilesOrTargetSourceFile?: ReadonlyArray | SourceFile, @@ -80,8 +80,8 @@ namespace ts { return Extension.Js; } - /*@internal*/ // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature + /*@internal*/ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile, emitOnlyDtsFiles?: boolean, transformers?: TransformerFactory[]): EmitResult { const compilerOptions = host.getCompilerOptions(); const sourceMapDataList: SourceMapData[] = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 06f15e1d77a50..0d2949a86d870 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -760,8 +760,8 @@ namespace ts { name: ComputedPropertyName; } - /* @internal */ // A declaration that supports late-binding (used in checker) + /* @internal */ export interface LateBoundDeclaration extends DynamicNamedDeclaration { name: LateBoundName; } @@ -775,8 +775,8 @@ namespace ts { expression: Expression; } - /* @internal */ // A name that supports late-binding (used in checker) + /* @internal */ export interface LateBoundName extends ComputedPropertyName { expression: EntityNameExpression; } @@ -3781,8 +3781,8 @@ namespace ts { export type StructuredType = ObjectType | UnionType | IntersectionType; - /* @internal */ // An instantiated anonymous type has a target and a mapper + /* @internal */ export interface AnonymousType extends ObjectType { target?: AnonymousType; // Instantiation target mapper?: TypeMapper; // Instantiation mapper @@ -3808,8 +3808,8 @@ namespace ts { mappedType: MappedType; } - /* @internal */ // Resolved object, union, or intersection type + /* @internal */ export interface ResolvedType extends ObjectType, UnionOrIntersectionType { members: SymbolTable; // Properties by name properties: Symbol[]; // Properties From 5addfab0bd632a0f254609b9f22727620e2aa148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Wed, 25 Apr 2018 18:57:44 +0800 Subject: [PATCH 06/11] fix internal type declaration again --- src/compiler/performance.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/performance.ts b/src/compiler/performance.ts index 104148ed4abeb..17451d3f55964 100644 --- a/src/compiler/performance.ts +++ b/src/compiler/performance.ts @@ -5,8 +5,8 @@ namespace ts { export const timestamp = typeof performance !== "undefined" && performance.now ? () => performance.now() : Date.now ? Date.now : () => +(new Date()); } -/*@internal*/ /** Performance measurements for the compiler. */ +/*@internal*/ namespace ts.performance { declare const onProfilerEvent: { (markName: string): void; profiler: boolean; }; From 169de4a1830a2de81bf3f6480cdb9a8d12b098de Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 25 Apr 2018 22:01:50 +0800 Subject: [PATCH 07/11] accept baseline --- src/compiler/types.ts | 2 +- .../reference/api/tsserverlibrary.d.ts | 66 +++++++++++++++++-- tests/baselines/reference/api/typescript.d.ts | 56 +++++++++++++++- 3 files changed, 116 insertions(+), 8 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0d2949a86d870..5e905eca3d8b8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3819,10 +3819,10 @@ namespace ts { numberIndexInfo?: IndexInfo; // Numeric indexing info } - /* @internal */ // Object literals are initially marked fresh. Freshness disappears following an assignment, // before a type assertion, or when an object literal's type is widened. The regular // version of a fresh type is identical except for the TypeFlags.FreshObjectLiteral flag. + /* @internal */ export interface FreshObjectLiteralType extends ResolvedType { regularType: ResolvedType; // Regular version of fresh type } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 1f5757ff4ced7..864186803d926 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1619,6 +1619,13 @@ declare namespace ts { path: string; name: string; } + /** + * Subset of properties from SourceFile that are used in multiple utility functions + */ + interface SourceFileLike { + readonly text: string; + lineMap?: ReadonlyArray; + } interface SourceFile extends Declaration { kind: SyntaxKind.SourceFile; statements: NodeArray; @@ -2011,7 +2018,8 @@ declare namespace ts { HasMembers = 6240, BlockScoped = 418, PropertyOrAccessor = 98308, - ClassMember = 106500 + ClassMember = 106500, + Classifiable = 2885600 } interface Symbol { flags: SymbolFlags; @@ -2123,6 +2131,9 @@ declare namespace ts { aliasSymbol?: Symbol; aliasTypeArguments?: Type[]; } + interface IntrinsicType extends Type { + intrinsicName: string; + } interface LiteralType extends Type { value: string | number; freshType?: LiteralType; @@ -2247,6 +2258,8 @@ declare namespace ts { declaration?: SignatureDeclaration; typeParameters?: TypeParameter[]; parameters: Symbol[]; + resolvedReturnType: Type | undefined; + resolvedTypePredicate: TypePredicate | undefined; } enum IndexKind { String = 0, @@ -2965,6 +2978,10 @@ declare namespace ts { } function tokenToString(t: SyntaxKind): string | undefined; function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; + /** + * We assume the first line starts at position 0 and 'position' is non-negative. + */ + function computeLineAndCharacterOfPosition(lineStarts: ReadonlyArray, position: number): LineAndCharacter; function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; function isWhiteSpaceLike(ch: number): boolean; /** Does not include line breaks. For that, see isWhiteSpaceLike. */ @@ -2975,9 +2992,9 @@ declare namespace ts { function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; + function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U, inline?: boolean): U; function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; - function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined; + function getLeadingCommentRanges(text: string, pos: number, inline?: boolean): CommentRange[] | undefined; function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined; /** Optionally, get the shebang */ function getShebang(text: string): string | undefined; @@ -3324,6 +3341,11 @@ declare namespace ts { function isCallLikeExpression(node: Node): node is CallLikeExpression; function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression; function isTemplateLiteral(node: Node): node is TemplateLiteral; + /** + * Determines whether a node is an expression based only on its kind. + * Use `isExpressionNode` if not in transforms. + */ + function isExpression(node: Node): node is Expression; function isAssertionExpression(node: Node): node is AssertionExpression; function isIterationStatement(node: Node, lookInLabeledStatements: false): node is IterationStatement; function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is IterationStatement | LabeledStatement; @@ -3362,6 +3384,10 @@ declare namespace ts { function parseJsonText(fileName: string, sourceText: string): JsonSourceFile; function isExternalModule(file: SourceFile): boolean; function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; + function parseJSDocTypeExpressionForTests(content: string, start?: number, length?: number): { + jsDocTypeExpression: JSDocTypeExpression; + diagnostics: Diagnostic[]; + }; } declare namespace ts { interface GetEffectiveTypeRootsHost { @@ -3929,6 +3955,12 @@ declare namespace ts { * @returns A 'Program' object. */ function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; + /** + * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. + * The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to. + * This returns a diagnostic even if the module will be an untyped module. + */ + function getResolutionDiagnostic(options: CompilerOptions, { extension }: ResolvedModuleFull): DiagnosticMessage | undefined; } declare namespace ts { interface EmitOutput { @@ -4242,7 +4274,9 @@ declare namespace ts { getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node; getChildren(sourceFile?: SourceFile): Node[]; + getChildren(sourceFile?: SourceFileLike): Node[]; getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; + getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; getFullStart(): number; getEnd(): number; getWidth(sourceFile?: SourceFile): number; @@ -5046,6 +5080,11 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24 } } +interface PromiseConstructor { + new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Promise; + reject(reason: any): Promise; + all(values: (T | PromiseLike)[]): Promise; +} declare namespace ts { function createClassifier(): Classifier; } @@ -5145,7 +5184,18 @@ declare namespace ts { function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; + /** A cancellation that throttles calls to the host */ + class ThrottledCancellationToken implements CancellationToken { + private hostCancellationToken; + private readonly throttleWaitMilliseconds; + private lastCancellationCheckTime; + constructor(hostCancellationToken: HostCancellationToken, throttleWaitMilliseconds?: number); + isCancellationRequested(): boolean; + throwIfCancellationRequested(): void; + } function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnly?: boolean): LanguageService; + /** Names in the name table are escaped, so an identifier `__foo` will have a name table entry `___foo`. */ + function getNameTable(sourceFile: SourceFile): UnderscoreEscapedMap; /** * Get the path of the default library files (lib.d.ts) as distributed with the typescript * node package. @@ -7581,6 +7631,8 @@ declare namespace ts.server { private formatSettings; private preferences; private textStorage; + /** Set to real path if path is different from info.path */ + private realpath; constructor(host: ServerHost, fileName: NormalizedPath, scriptKind: ScriptKind, hasMixedContent: boolean, path: Path); isScriptOpen(): boolean; open(newText: string): void; @@ -7658,7 +7710,6 @@ declare namespace ts.server { */ type ProjectRoot = ScriptInfo | NormalizedPath; abstract class Project implements LanguageServiceHost, ModuleResolutionHost { - readonly projectName: string; readonly projectKind: ProjectKind; readonly projectService: ProjectService; private documentRegistry; @@ -7670,6 +7721,12 @@ declare namespace ts.server { private externalFiles; private missingFilesMap; private plugins; + /** + * This is map from files to unresolved imports in it + * Maop does not contain entries for files that do not have unresolved imports + * This helps in containing the set of files to invalidate + */ + cachedUnresolvedImportsPerFile: Map>; private lastFileExceededProgramSize; protected languageService: LanguageService; languageServiceEnabled: boolean; @@ -8366,6 +8423,7 @@ declare namespace ts.server { response?: {}; responseRequired?: boolean; } + function getLocationInNewDocument(oldText: string, renameFilename: string, renameLocation: number, edits: ReadonlyArray): protocol.Location; } export = ts; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3c47002061ffc..9d26014639ea8 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1619,6 +1619,13 @@ declare namespace ts { path: string; name: string; } + /** + * Subset of properties from SourceFile that are used in multiple utility functions + */ + interface SourceFileLike { + readonly text: string; + lineMap?: ReadonlyArray; + } interface SourceFile extends Declaration { kind: SyntaxKind.SourceFile; statements: NodeArray; @@ -2011,7 +2018,8 @@ declare namespace ts { HasMembers = 6240, BlockScoped = 418, PropertyOrAccessor = 98308, - ClassMember = 106500 + ClassMember = 106500, + Classifiable = 2885600 } interface Symbol { flags: SymbolFlags; @@ -2123,6 +2131,9 @@ declare namespace ts { aliasSymbol?: Symbol; aliasTypeArguments?: Type[]; } + interface IntrinsicType extends Type { + intrinsicName: string; + } interface LiteralType extends Type { value: string | number; freshType?: LiteralType; @@ -2247,6 +2258,8 @@ declare namespace ts { declaration?: SignatureDeclaration; typeParameters?: TypeParameter[]; parameters: Symbol[]; + resolvedReturnType: Type | undefined; + resolvedTypePredicate: TypePredicate | undefined; } enum IndexKind { String = 0, @@ -2965,6 +2978,10 @@ declare namespace ts { } function tokenToString(t: SyntaxKind): string | undefined; function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; + /** + * We assume the first line starts at position 0 and 'position' is non-negative. + */ + function computeLineAndCharacterOfPosition(lineStarts: ReadonlyArray, position: number): LineAndCharacter; function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; function isWhiteSpaceLike(ch: number): boolean; /** Does not include line breaks. For that, see isWhiteSpaceLike. */ @@ -2975,9 +2992,9 @@ declare namespace ts { function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; + function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U, inline?: boolean): U; function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; - function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined; + function getLeadingCommentRanges(text: string, pos: number, inline?: boolean): CommentRange[] | undefined; function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined; /** Optionally, get the shebang */ function getShebang(text: string): string | undefined; @@ -3324,6 +3341,11 @@ declare namespace ts { function isCallLikeExpression(node: Node): node is CallLikeExpression; function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression; function isTemplateLiteral(node: Node): node is TemplateLiteral; + /** + * Determines whether a node is an expression based only on its kind. + * Use `isExpressionNode` if not in transforms. + */ + function isExpression(node: Node): node is Expression; function isAssertionExpression(node: Node): node is AssertionExpression; function isIterationStatement(node: Node, lookInLabeledStatements: false): node is IterationStatement; function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is IterationStatement | LabeledStatement; @@ -3362,6 +3384,10 @@ declare namespace ts { function parseJsonText(fileName: string, sourceText: string): JsonSourceFile; function isExternalModule(file: SourceFile): boolean; function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; + function parseJSDocTypeExpressionForTests(content: string, start?: number, length?: number): { + jsDocTypeExpression: JSDocTypeExpression; + diagnostics: Diagnostic[]; + }; } declare namespace ts { interface GetEffectiveTypeRootsHost { @@ -3929,6 +3955,12 @@ declare namespace ts { * @returns A 'Program' object. */ function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; + /** + * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. + * The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to. + * This returns a diagnostic even if the module will be an untyped module. + */ + function getResolutionDiagnostic(options: CompilerOptions, { extension }: ResolvedModuleFull): DiagnosticMessage | undefined; } declare namespace ts { interface EmitOutput { @@ -4242,7 +4274,9 @@ declare namespace ts { getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node; getChildren(sourceFile?: SourceFile): Node[]; + getChildren(sourceFile?: SourceFileLike): Node[]; getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; + getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; getFullStart(): number; getEnd(): number; getWidth(sourceFile?: SourceFile): number; @@ -5046,6 +5080,11 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24 } } +interface PromiseConstructor { + new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Promise; + reject(reason: any): Promise; + all(values: (T | PromiseLike)[]): Promise; +} declare namespace ts { function createClassifier(): Classifier; } @@ -5145,7 +5184,18 @@ declare namespace ts { function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; + /** A cancellation that throttles calls to the host */ + class ThrottledCancellationToken implements CancellationToken { + private hostCancellationToken; + private readonly throttleWaitMilliseconds; + private lastCancellationCheckTime; + constructor(hostCancellationToken: HostCancellationToken, throttleWaitMilliseconds?: number); + isCancellationRequested(): boolean; + throwIfCancellationRequested(): void; + } function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnly?: boolean): LanguageService; + /** Names in the name table are escaped, so an identifier `__foo` will have a name table entry `___foo`. */ + function getNameTable(sourceFile: SourceFile): UnderscoreEscapedMap; /** * Get the path of the default library files (lib.d.ts) as distributed with the typescript * node package. From 9efa90e236c7fc84de08d7d1a5a874e46af311aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Fri, 27 Apr 2018 14:05:15 +0800 Subject: [PATCH 08/11] refactor inline --- src/compiler/emitter.ts | 4 +- src/compiler/performance.ts | 2 +- src/compiler/scanner.ts | 12 ++-- src/compiler/transformers/declarations.ts | 33 ++++++++-- src/compiler/types.ts | 10 +-- src/compiler/utilities.ts | 8 ++- .../reference/api/tsserverlibrary.d.ts | 65 +----------------- tests/baselines/reference/api/typescript.d.ts | 56 +--------------- .../declarationEmitWorkWithInlineComments.js | 66 +++++++++++++++---- ...larationEmitWorkWithInlineComments.symbols | 39 +++++++++-- ...eclarationEmitWorkWithInlineComments.types | 35 ++++++++-- .../declarationEmitWorkWithInlineComments.ts | 25 +++++-- 12 files changed, 190 insertions(+), 165 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9dddacdcf10a7..2b01f2fdda1bc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1,6 +1,7 @@ namespace ts { const brackets = createBracketsMap(); + /*@internal*/ /** * Iterates over the source files that are expected to have an emit output. * @@ -10,7 +11,6 @@ namespace ts { * If an array, the full list of source files to emit. * Else, calls `getSourceFilesToEmit` with the (optional) target source file to determine the list of source files to emit. */ - /*@internal*/ export function forEachEmittedFile( host: EmitHost, action: (emitFileNames: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle) => T, sourceFilesOrTargetSourceFile?: ReadonlyArray | SourceFile, @@ -80,8 +80,8 @@ namespace ts { return Extension.Js; } - // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature /*@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[]): EmitResult { const compilerOptions = host.getCompilerOptions(); const sourceMapDataList: SourceMapData[] = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined; diff --git a/src/compiler/performance.ts b/src/compiler/performance.ts index 17451d3f55964..104148ed4abeb 100644 --- a/src/compiler/performance.ts +++ b/src/compiler/performance.ts @@ -5,8 +5,8 @@ namespace ts { export const timestamp = typeof performance !== "undefined" && performance.now ? () => performance.now() : Date.now ? Date.now : () => +(new Date()); } -/** Performance measurements for the compiler. */ /*@internal*/ +/** Performance measurements for the compiler. */ namespace ts.performance { declare const onProfilerEvent: { (markName: string): void; profiler: boolean; }; diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 64565134f2372..f2a01d22c2480 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -626,13 +626,13 @@ namespace ts { * @returns If "reduce" is true, the accumulated value. If "reduce" is false, the first truthy * return value of the callback. */ - function iterateCommentRanges(reduce: boolean, text: string, pos: number, trailing: boolean, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial?: U, inline?: boolean): U { + function iterateCommentRanges(reduce: boolean, text: string, pos: number, trailing: boolean, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial?: U): U { let pendingPos: number; let pendingEnd: number; let pendingKind: CommentKind; let pendingHasTrailingNewLine: boolean; let hasPendingCommentRange = false; - let collecting = inline || trailing || pos === 0; + let collecting = trailing || pos === 0; let accumulator = initial; scan: while (pos >= 0 && pos < text.length) { const ch = text.charCodeAt(pos); @@ -736,8 +736,8 @@ namespace ts { return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ true, cb, state); } - export function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U, inline?: boolean) { - return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ false, cb, state, initial, inline); + export function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U) { + return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ false, cb, state, initial); } export function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U) { @@ -753,8 +753,8 @@ namespace ts { return comments; } - export function getLeadingCommentRanges(text: string, pos: number, inline?: boolean): CommentRange[] | undefined { - return reduceEachLeadingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined, inline); + export function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined { + return reduceEachLeadingCommentRange(text, pos, appendCommentRange, /*state*/ undefined, /*initial*/ undefined); } export function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined { diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 2711970cf8e97..78b51d8cd6b90 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -964,8 +964,11 @@ namespace ts { let parameterProperties: PropertyDeclaration[]; if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; - parameterProperties = compact(flatMap(ctor.parameters, param => { - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param, /* inline */ true)) return; + let previousSibling: Node; + parameterProperties = compact(flatMap(ctor.parameters, (param) => { + const shouldStrip = shouldStripInternalParameter(param, previousSibling); + previousSibling = param; + if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStrip) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1140,10 +1143,30 @@ namespace ts { return stringContains(comment, "@internal"); } - function shouldStripInternal(node: Node, inline?: boolean) { + function shouldStripInternal(node: Node) { if (stripInternal && node) { - const leadingCommentRanges = getLeadingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile, inline); - return length(leadingCommentRanges) && hasInternalAnnotation(last(leadingCommentRanges)); + const leadingCommentRanges = getLeadingCommentRangesOfNode(getParseTreeNode(node), currentSourceFile); + if (forEach(leadingCommentRanges, hasInternalAnnotation)) { + return true; + } + } + return false; + } + + function shouldStripInternalParameter(node: Node, previousSibling: Node | undefined) { + if (stripInternal && node) { + node = getParseTreeNode(node) + const text = currentSourceFile.text; + const commentRanges = previousSibling + ? concatenate( + // to handle + // ... parameters, /* @internal */ + // public param: string + getTrailingCommentRanges(text, skipTrivia(text, previousSibling.end + 1, /* stopAfterLineBreak */ false, /* stopAtComments */ true)), + getLeadingCommentRanges(text, node.pos) + ) + : getTrailingCommentRanges(text, skipTrivia(text, node.pos, /* stopAfterLineBreak */ false, /* stopAtComments */ true)); + return length(commentRanges) && hasInternalAnnotation(last(commentRanges)); } return false; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5e905eca3d8b8..06f15e1d77a50 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -760,8 +760,8 @@ namespace ts { name: ComputedPropertyName; } - // A declaration that supports late-binding (used in checker) /* @internal */ + // A declaration that supports late-binding (used in checker) export interface LateBoundDeclaration extends DynamicNamedDeclaration { name: LateBoundName; } @@ -775,8 +775,8 @@ namespace ts { expression: Expression; } - // A name that supports late-binding (used in checker) /* @internal */ + // A name that supports late-binding (used in checker) export interface LateBoundName extends ComputedPropertyName { expression: EntityNameExpression; } @@ -3781,8 +3781,8 @@ namespace ts { export type StructuredType = ObjectType | UnionType | IntersectionType; - // An instantiated anonymous type has a target and a mapper /* @internal */ + // An instantiated anonymous type has a target and a mapper export interface AnonymousType extends ObjectType { target?: AnonymousType; // Instantiation target mapper?: TypeMapper; // Instantiation mapper @@ -3808,8 +3808,8 @@ namespace ts { mappedType: MappedType; } - // Resolved object, union, or intersection type /* @internal */ + // Resolved object, union, or intersection type export interface ResolvedType extends ObjectType, UnionOrIntersectionType { members: SymbolTable; // Properties by name properties: Symbol[]; // Properties @@ -3819,10 +3819,10 @@ namespace ts { numberIndexInfo?: IndexInfo; // Numeric indexing info } + /* @internal */ // Object literals are initially marked fresh. Freshness disappears following an assignment, // before a type assertion, or when an object literal's type is widened. The regular // version of a fresh type is identical except for the TypeFlags.FreshObjectLiteral flag. - /* @internal */ export interface FreshObjectLiteralType extends ResolvedType { regularType: ResolvedType; // Regular version of fresh type } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 07bcff6bf9d23..14f82b2841161 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -754,8 +754,12 @@ namespace ts { && (node).expression.kind === SyntaxKind.StringLiteral; } - export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile, inline?: boolean) { - return node.kind !== SyntaxKind.JsxText ? getLeadingCommentRanges(sourceFileOfNode.text, node.pos, inline) : undefined; + export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { + return node.kind !== SyntaxKind.JsxText ? getLeadingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; + } + + export function getTrailingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { + return node.kind !== SyntaxKind.JsxText ? getTrailingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; } export function getJSDocCommentRanges(node: Node, text: string) { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 864186803d926..bcaf38e0ab0e2 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1619,13 +1619,6 @@ declare namespace ts { path: string; name: string; } - /** - * Subset of properties from SourceFile that are used in multiple utility functions - */ - interface SourceFileLike { - readonly text: string; - lineMap?: ReadonlyArray; - } interface SourceFile extends Declaration { kind: SyntaxKind.SourceFile; statements: NodeArray; @@ -2018,8 +2011,7 @@ declare namespace ts { HasMembers = 6240, BlockScoped = 418, PropertyOrAccessor = 98308, - ClassMember = 106500, - Classifiable = 2885600 + ClassMember = 106500 } interface Symbol { flags: SymbolFlags; @@ -2131,9 +2123,6 @@ declare namespace ts { aliasSymbol?: Symbol; aliasTypeArguments?: Type[]; } - interface IntrinsicType extends Type { - intrinsicName: string; - } interface LiteralType extends Type { value: string | number; freshType?: LiteralType; @@ -2258,8 +2247,6 @@ declare namespace ts { declaration?: SignatureDeclaration; typeParameters?: TypeParameter[]; parameters: Symbol[]; - resolvedReturnType: Type | undefined; - resolvedTypePredicate: TypePredicate | undefined; } enum IndexKind { String = 0, @@ -2978,10 +2965,6 @@ declare namespace ts { } function tokenToString(t: SyntaxKind): string | undefined; function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; - /** - * We assume the first line starts at position 0 and 'position' is non-negative. - */ - function computeLineAndCharacterOfPosition(lineStarts: ReadonlyArray, position: number): LineAndCharacter; function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; function isWhiteSpaceLike(ch: number): boolean; /** Does not include line breaks. For that, see isWhiteSpaceLike. */ @@ -2992,9 +2975,9 @@ declare namespace ts { function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U, inline?: boolean): U; + function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; - function getLeadingCommentRanges(text: string, pos: number, inline?: boolean): CommentRange[] | undefined; + function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined; function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined; /** Optionally, get the shebang */ function getShebang(text: string): string | undefined; @@ -3341,11 +3324,6 @@ declare namespace ts { function isCallLikeExpression(node: Node): node is CallLikeExpression; function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression; function isTemplateLiteral(node: Node): node is TemplateLiteral; - /** - * Determines whether a node is an expression based only on its kind. - * Use `isExpressionNode` if not in transforms. - */ - function isExpression(node: Node): node is Expression; function isAssertionExpression(node: Node): node is AssertionExpression; function isIterationStatement(node: Node, lookInLabeledStatements: false): node is IterationStatement; function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is IterationStatement | LabeledStatement; @@ -3384,10 +3362,6 @@ declare namespace ts { function parseJsonText(fileName: string, sourceText: string): JsonSourceFile; function isExternalModule(file: SourceFile): boolean; function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - function parseJSDocTypeExpressionForTests(content: string, start?: number, length?: number): { - jsDocTypeExpression: JSDocTypeExpression; - diagnostics: Diagnostic[]; - }; } declare namespace ts { interface GetEffectiveTypeRootsHost { @@ -3955,12 +3929,6 @@ declare namespace ts { * @returns A 'Program' object. */ function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; - /** - * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. - * The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to. - * This returns a diagnostic even if the module will be an untyped module. - */ - function getResolutionDiagnostic(options: CompilerOptions, { extension }: ResolvedModuleFull): DiagnosticMessage | undefined; } declare namespace ts { interface EmitOutput { @@ -4274,9 +4242,7 @@ declare namespace ts { getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node; getChildren(sourceFile?: SourceFile): Node[]; - getChildren(sourceFile?: SourceFileLike): Node[]; getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; - getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; getFullStart(): number; getEnd(): number; getWidth(sourceFile?: SourceFile): number; @@ -5080,11 +5046,6 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24 } } -interface PromiseConstructor { - new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Promise; - reject(reason: any): Promise; - all(values: (T | PromiseLike)[]): Promise; -} declare namespace ts { function createClassifier(): Classifier; } @@ -5184,18 +5145,7 @@ declare namespace ts { function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - /** A cancellation that throttles calls to the host */ - class ThrottledCancellationToken implements CancellationToken { - private hostCancellationToken; - private readonly throttleWaitMilliseconds; - private lastCancellationCheckTime; - constructor(hostCancellationToken: HostCancellationToken, throttleWaitMilliseconds?: number); - isCancellationRequested(): boolean; - throwIfCancellationRequested(): void; - } function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnly?: boolean): LanguageService; - /** Names in the name table are escaped, so an identifier `__foo` will have a name table entry `___foo`. */ - function getNameTable(sourceFile: SourceFile): UnderscoreEscapedMap; /** * Get the path of the default library files (lib.d.ts) as distributed with the typescript * node package. @@ -7631,8 +7581,6 @@ declare namespace ts.server { private formatSettings; private preferences; private textStorage; - /** Set to real path if path is different from info.path */ - private realpath; constructor(host: ServerHost, fileName: NormalizedPath, scriptKind: ScriptKind, hasMixedContent: boolean, path: Path); isScriptOpen(): boolean; open(newText: string): void; @@ -7721,12 +7669,6 @@ declare namespace ts.server { private externalFiles; private missingFilesMap; private plugins; - /** - * This is map from files to unresolved imports in it - * Maop does not contain entries for files that do not have unresolved imports - * This helps in containing the set of files to invalidate - */ - cachedUnresolvedImportsPerFile: Map>; private lastFileExceededProgramSize; protected languageService: LanguageService; languageServiceEnabled: boolean; @@ -8423,7 +8365,6 @@ declare namespace ts.server { response?: {}; responseRequired?: boolean; } - function getLocationInNewDocument(oldText: string, renameFilename: string, renameLocation: number, edits: ReadonlyArray): protocol.Location; } export = ts; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 9d26014639ea8..3c47002061ffc 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1619,13 +1619,6 @@ declare namespace ts { path: string; name: string; } - /** - * Subset of properties from SourceFile that are used in multiple utility functions - */ - interface SourceFileLike { - readonly text: string; - lineMap?: ReadonlyArray; - } interface SourceFile extends Declaration { kind: SyntaxKind.SourceFile; statements: NodeArray; @@ -2018,8 +2011,7 @@ declare namespace ts { HasMembers = 6240, BlockScoped = 418, PropertyOrAccessor = 98308, - ClassMember = 106500, - Classifiable = 2885600 + ClassMember = 106500 } interface Symbol { flags: SymbolFlags; @@ -2131,9 +2123,6 @@ declare namespace ts { aliasSymbol?: Symbol; aliasTypeArguments?: Type[]; } - interface IntrinsicType extends Type { - intrinsicName: string; - } interface LiteralType extends Type { value: string | number; freshType?: LiteralType; @@ -2258,8 +2247,6 @@ declare namespace ts { declaration?: SignatureDeclaration; typeParameters?: TypeParameter[]; parameters: Symbol[]; - resolvedReturnType: Type | undefined; - resolvedTypePredicate: TypePredicate | undefined; } enum IndexKind { String = 0, @@ -2978,10 +2965,6 @@ declare namespace ts { } function tokenToString(t: SyntaxKind): string | undefined; function getPositionOfLineAndCharacter(sourceFile: SourceFileLike, line: number, character: number): number; - /** - * We assume the first line starts at position 0 and 'position' is non-negative. - */ - function computeLineAndCharacterOfPosition(lineStarts: ReadonlyArray, position: number): LineAndCharacter; function getLineAndCharacterOfPosition(sourceFile: SourceFileLike, position: number): LineAndCharacter; function isWhiteSpaceLike(ch: number): boolean; /** Does not include line breaks. For that, see isWhiteSpaceLike. */ @@ -2992,9 +2975,9 @@ declare namespace ts { function forEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean) => U): U | undefined; function forEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T) => U, state: T): U | undefined; - function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U, inline?: boolean): U; + function reduceEachLeadingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; function reduceEachTrailingCommentRange(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U): U; - function getLeadingCommentRanges(text: string, pos: number, inline?: boolean): CommentRange[] | undefined; + function getLeadingCommentRanges(text: string, pos: number): CommentRange[] | undefined; function getTrailingCommentRanges(text: string, pos: number): CommentRange[] | undefined; /** Optionally, get the shebang */ function getShebang(text: string): string | undefined; @@ -3341,11 +3324,6 @@ declare namespace ts { function isCallLikeExpression(node: Node): node is CallLikeExpression; function isCallOrNewExpression(node: Node): node is CallExpression | NewExpression; function isTemplateLiteral(node: Node): node is TemplateLiteral; - /** - * Determines whether a node is an expression based only on its kind. - * Use `isExpressionNode` if not in transforms. - */ - function isExpression(node: Node): node is Expression; function isAssertionExpression(node: Node): node is AssertionExpression; function isIterationStatement(node: Node, lookInLabeledStatements: false): node is IterationStatement; function isIterationStatement(node: Node, lookInLabeledStatements: boolean): node is IterationStatement | LabeledStatement; @@ -3384,10 +3362,6 @@ declare namespace ts { function parseJsonText(fileName: string, sourceText: string): JsonSourceFile; function isExternalModule(file: SourceFile): boolean; function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - function parseJSDocTypeExpressionForTests(content: string, start?: number, length?: number): { - jsDocTypeExpression: JSDocTypeExpression; - diagnostics: Diagnostic[]; - }; } declare namespace ts { interface GetEffectiveTypeRootsHost { @@ -3955,12 +3929,6 @@ declare namespace ts { * @returns A 'Program' object. */ function createProgram(rootNames: ReadonlyArray, options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: ReadonlyArray): Program; - /** - * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. - * The DiagnosticMessage's parameters are the imported module name, and the filename it resolved to. - * This returns a diagnostic even if the module will be an untyped module. - */ - function getResolutionDiagnostic(options: CompilerOptions, { extension }: ResolvedModuleFull): DiagnosticMessage | undefined; } declare namespace ts { interface EmitOutput { @@ -4274,9 +4242,7 @@ declare namespace ts { getChildCount(sourceFile?: SourceFile): number; getChildAt(index: number, sourceFile?: SourceFile): Node; getChildren(sourceFile?: SourceFile): Node[]; - getChildren(sourceFile?: SourceFileLike): Node[]; getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; - getStart(sourceFile?: SourceFileLike, includeJsDocComment?: boolean): number; getFullStart(): number; getEnd(): number; getWidth(sourceFile?: SourceFile): number; @@ -5080,11 +5046,6 @@ declare namespace ts { jsxAttributeStringLiteralValue = 24 } } -interface PromiseConstructor { - new (executor: (resolve: (value?: T | PromiseLike) => void, reject: (reason?: any) => void) => void): Promise; - reject(reason: any): Promise; - all(values: (T | PromiseLike)[]): Promise; -} declare namespace ts { function createClassifier(): Classifier; } @@ -5184,18 +5145,7 @@ declare namespace ts { function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - /** A cancellation that throttles calls to the host */ - class ThrottledCancellationToken implements CancellationToken { - private hostCancellationToken; - private readonly throttleWaitMilliseconds; - private lastCancellationCheckTime; - constructor(hostCancellationToken: HostCancellationToken, throttleWaitMilliseconds?: number); - isCancellationRequested(): boolean; - throwIfCancellationRequested(): void; - } function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnly?: boolean): LanguageService; - /** Names in the name table are escaped, so an identifier `__foo` will have a name table entry `___foo`. */ - function getNameTable(sourceFile: SourceFile): UnderscoreEscapedMap; /** * Get the path of the default library files (lib.d.ts) as distributed with the typescript * node package. diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.js b/tests/baselines/reference/declarationEmitWorkWithInlineComments.js index 3f762facb78d9..391c5d544b28f 100644 --- a/tests/baselines/reference/declarationEmitWorkWithInlineComments.js +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.js @@ -7,18 +7,32 @@ export class Foo { public isInternal3: string, // @internal public isInternal4: string, - // @internal + // nothing /** @internal */ public isInternal5: string, - /* @internal */ public isInternal6: string, /** @internal */ - // next line + /* @internal */ public isInternal6: string /* trailing */, + /* @internal */ public isInternal7: string, /** @internal */ + // not work public notInternal1: string, // @internal - /* next line */ - public notInternal2: string + /* not work */ + public notInternal2: string, + /* not work */ + // @internal + /* not work */ + public notInternal3: string, ) { } } - + +export class Bar { + constructor(/* @internal */ public isInternal1: string) {} +} + +export class Baz { + constructor(/* @internal */ + public isInternal: string + ) {} +} //// [declarationEmitWorkWithInlineComments.js] "use strict"; @@ -30,37 +44,65 @@ var Foo = /** @class */ (function () { /** @internal */ isInternal2, /** @internal */ isInternal3, // @internal isInternal4, - // @internal + // nothing /** @internal */ isInternal5, - /* @internal */ isInternal6, /** @internal */ - // next line + /* @internal */ isInternal6 /* trailing */, + /* @internal */ isInternal7, /** @internal */ + // not work notInternal1, // @internal - /* next line */ - notInternal2) { + /* not work */ + notInternal2, + /* not work */ + // @internal + /* not work */ + notInternal3) { this.isInternal1 = isInternal1; this.isInternal2 = isInternal2; this.isInternal3 = isInternal3; this.isInternal4 = isInternal4; this.isInternal5 = isInternal5; this.isInternal6 = isInternal6; + this.isInternal7 = isInternal7; this.notInternal1 = notInternal1; this.notInternal2 = notInternal2; + this.notInternal3 = notInternal3; } return Foo; }()); exports.Foo = Foo; +var Bar = /** @class */ (function () { + function Bar(/* @internal */ isInternal1) { + this.isInternal1 = isInternal1; + } + return Bar; +}()); +exports.Bar = Bar; +var Baz = /** @class */ (function () { + function Baz(/* @internal */ isInternal) { + this.isInternal = isInternal; + } + return Baz; +}()); +exports.Baz = Baz; //// [declarationEmitWorkWithInlineComments.d.ts] export declare class Foo { notInternal1: string; notInternal2: string; + notInternal3: string; constructor( /** @internal */ isInternal1: string, /** @internal */ isInternal2: string, /** @internal */ isInternal3: string, isInternal4: string, /** @internal */ - isInternal5: string, isInternal6: string, /** @internal */ notInternal1: string, notInternal2: string); + isInternal5: string, isInternal6: string, isInternal7: string, /** @internal */ notInternal1: string, notInternal2: string, notInternal3: string); +} +export declare class Bar { + constructor(/* @internal */ isInternal1: string); +} +export declare class Baz { + constructor(/* @internal */ isInternal: string); } diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols b/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols index c541c67fa0c85..e1fecff590059 100644 --- a/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.symbols @@ -17,23 +17,48 @@ export class Foo { public isInternal4: string, >isInternal4 : Symbol(Foo.isInternal4, Decl(declarationEmitWorkWithInlineComments.ts, 5, 31)) - // @internal + // nothing /** @internal */ public isInternal5: string, >isInternal5 : Symbol(Foo.isInternal5, Decl(declarationEmitWorkWithInlineComments.ts, 7, 31)) - /* @internal */ public isInternal6: string, /** @internal */ + /* @internal */ public isInternal6: string /* trailing */, >isInternal6 : Symbol(Foo.isInternal6, Decl(declarationEmitWorkWithInlineComments.ts, 10, 31)) - // next line + /* @internal */ public isInternal7: string, /** @internal */ +>isInternal7 : Symbol(Foo.isInternal7, Decl(declarationEmitWorkWithInlineComments.ts, 11, 62)) + + // not work public notInternal1: string, ->notInternal1 : Symbol(Foo.notInternal1, Decl(declarationEmitWorkWithInlineComments.ts, 11, 47)) +>notInternal1 : Symbol(Foo.notInternal1, Decl(declarationEmitWorkWithInlineComments.ts, 12, 47)) // @internal - /* next line */ - public notInternal2: string ->notInternal2 : Symbol(Foo.notInternal2, Decl(declarationEmitWorkWithInlineComments.ts, 13, 32)) + /* not work */ + public notInternal2: string, +>notInternal2 : Symbol(Foo.notInternal2, Decl(declarationEmitWorkWithInlineComments.ts, 14, 32)) + + /* not work */ + // @internal + /* not work */ + public notInternal3: string, +>notInternal3 : Symbol(Foo.notInternal3, Decl(declarationEmitWorkWithInlineComments.ts, 17, 32)) ) { } } +export class Bar { +>Bar : Symbol(Bar, Decl(declarationEmitWorkWithInlineComments.ts, 23, 1)) + + constructor(/* @internal */ public isInternal1: string) {} +>isInternal1 : Symbol(Bar.isInternal1, Decl(declarationEmitWorkWithInlineComments.ts, 26, 14)) +} + +export class Baz { +>Baz : Symbol(Baz, Decl(declarationEmitWorkWithInlineComments.ts, 27, 1)) + + constructor(/* @internal */ + public isInternal: string +>isInternal : Symbol(Baz.isInternal, Decl(declarationEmitWorkWithInlineComments.ts, 30, 14)) + + ) {} +} diff --git a/tests/baselines/reference/declarationEmitWorkWithInlineComments.types b/tests/baselines/reference/declarationEmitWorkWithInlineComments.types index 3744bec8f51b8..dbde0b7ef2ccb 100644 --- a/tests/baselines/reference/declarationEmitWorkWithInlineComments.types +++ b/tests/baselines/reference/declarationEmitWorkWithInlineComments.types @@ -17,23 +17,48 @@ export class Foo { public isInternal4: string, >isInternal4 : string - // @internal + // nothing /** @internal */ public isInternal5: string, >isInternal5 : string - /* @internal */ public isInternal6: string, /** @internal */ + /* @internal */ public isInternal6: string /* trailing */, >isInternal6 : string - // next line + /* @internal */ public isInternal7: string, /** @internal */ +>isInternal7 : string + + // not work public notInternal1: string, >notInternal1 : string // @internal - /* next line */ - public notInternal2: string + /* not work */ + public notInternal2: string, >notInternal2 : string + /* not work */ + // @internal + /* not work */ + public notInternal3: string, +>notInternal3 : string + ) { } } +export class Bar { +>Bar : Bar + + constructor(/* @internal */ public isInternal1: string) {} +>isInternal1 : string +} + +export class Baz { +>Baz : Baz + + constructor(/* @internal */ + public isInternal: string +>isInternal : string + + ) {} +} diff --git a/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts b/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts index 135e08c202527..a5b3074a5cb63 100644 --- a/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts +++ b/tests/cases/conformance/declarationEmit/declarationEmitWorkWithInlineComments.ts @@ -9,14 +9,29 @@ export class Foo { public isInternal3: string, // @internal public isInternal4: string, - // @internal + // nothing /** @internal */ public isInternal5: string, - /* @internal */ public isInternal6: string, /** @internal */ - // next line + /* @internal */ public isInternal6: string /* trailing */, + /* @internal */ public isInternal7: string, /** @internal */ + // not work public notInternal1: string, // @internal - /* next line */ - public notInternal2: string + /* not work */ + public notInternal2: string, + /* not work */ + // @internal + /* not work */ + public notInternal3: string, ) { } } + +export class Bar { + constructor(/* @internal */ public isInternal1: string) {} +} + +export class Baz { + constructor(/* @internal */ + public isInternal: string + ) {} +} \ No newline at end of file From bd6e02fdcbbef719e3a77662d9252ad69b7a4e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Fri, 27 Apr 2018 14:21:11 +0800 Subject: [PATCH 09/11] simply prev check --- src/compiler/transformers/declarations.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 78b51d8cd6b90..d1b253ee75fb0 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -966,9 +966,8 @@ namespace ts { const oldDiag = getSymbolAccessibilityDiagnostic; let previousSibling: Node; parameterProperties = compact(flatMap(ctor.parameters, (param) => { - const shouldStrip = shouldStripInternalParameter(param, previousSibling); - previousSibling = param; - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStrip) return; + const prev = previousSibling; + if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternalParameter((previousSibling = param), prev)) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1155,7 +1154,7 @@ namespace ts { function shouldStripInternalParameter(node: Node, previousSibling: Node | undefined) { if (stripInternal && node) { - node = getParseTreeNode(node) + node = getParseTreeNode(node); const text = currentSourceFile.text; const commentRanges = previousSibling ? concatenate( From ea12d9e7a3ac9acabee675356a6f382a3c7ac394 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Fri, 27 Apr 2018 14:32:43 +0800 Subject: [PATCH 10/11] remove getTrailingCommentRangesOfNode --- src/compiler/utilities.ts | 4 ---- src/server/project.ts | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 14f82b2841161..c5cb19e876a6f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -758,10 +758,6 @@ namespace ts { return node.kind !== SyntaxKind.JsxText ? getLeadingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; } - export function getTrailingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { - return node.kind !== SyntaxKind.JsxText ? getTrailingCommentRanges(sourceFileOfNode.text, node.pos) : undefined; - } - export function getJSDocCommentRanges(node: Node, text: string) { const commentRanges = (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter || diff --git a/src/server/project.ts b/src/server/project.ts index 92645cfca5248..b045b551fc1ca 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -187,7 +187,7 @@ namespace ts.server { /*@internal*/ constructor( - /*@internal*/readonly projectName: string, + /*@internal*/ readonly projectName: string, readonly projectKind: ProjectKind, readonly projectService: ProjectService, private documentRegistry: DocumentRegistry, From 216a3806cc87147c451436351f5e942f111279a4 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 12 Mar 2019 12:57:11 -0700 Subject: [PATCH 11/11] Merge implementation with new isInternalDeclaration method, accept lkg-based baseline --- src/compiler/transformers/declarations.ts | 45 +++++++++---------- .../reference/api/tsserverlibrary.d.ts | 1 + 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 2c85a7d1861fa..15d7cb6ff5fa5 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -9,12 +9,31 @@ namespace ts { return result.diagnostics; } + function hasInternalAnnotation(range: CommentRange, currentSourceFile: SourceFile) { + const comment = currentSourceFile.text.substring(range.pos, range.end); + return stringContains(comment, "@internal"); + } + export function isInternalDeclaration(node: Node, currentSourceFile: SourceFile) { const parseTreeNode = getParseTreeNode(node); + if (parseTreeNode && parseTreeNode.kind === SyntaxKind.Parameter) { + const paramIdx = (parseTreeNode.parent as FunctionLike).parameters.indexOf(parseTreeNode as ParameterDeclaration); + const previousSibling = paramIdx > 0 ? (parseTreeNode.parent as FunctionLike).parameters[paramIdx - 1] : undefined; + const text = currentSourceFile.text; + const commentRanges = previousSibling + ? concatenate( + // to handle + // ... parameters, /* @internal */ + // public param: string + getTrailingCommentRanges(text, skipTrivia(text, previousSibling.end + 1, /* stopAfterLineBreak */ false, /* stopAtComments */ true)), + getLeadingCommentRanges(text, node.pos) + ) + : getTrailingCommentRanges(text, skipTrivia(text, node.pos, /* stopAfterLineBreak */ false, /* stopAtComments */ true)); + return commentRanges && commentRanges.length && hasInternalAnnotation(last(commentRanges), currentSourceFile); + } const leadingCommentRanges = parseTreeNode && getLeadingCommentRangesOfNode(parseTreeNode, currentSourceFile); return !!forEach(leadingCommentRanges, range => { - const comment = currentSourceFile.text.substring(range.pos, range.end); - return stringContains(comment, "@internal"); + return hasInternalAnnotation(range, currentSourceFile); }); } @@ -1075,10 +1094,8 @@ namespace ts { let parameterProperties: ReadonlyArray | undefined; if (ctor) { const oldDiag = getSymbolAccessibilityDiagnostic; - let previousSibling: Node; parameterProperties = compact(flatMap(ctor.parameters, (param) => { - const prev = previousSibling; - if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternalParameter((previousSibling = param), prev)) return; + if (!hasModifier(param, ModifierFlags.ParameterPropertyModifier) || shouldStripInternal(param)) return; getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode(param); if (param.name.kind === SyntaxKind.Identifier) { return preserveJsDoc(createProperty( @@ -1243,24 +1260,6 @@ namespace ts { return !!stripInternal && !!node && isInternalDeclaration(node, currentSourceFile); } - function shouldStripInternalParameter(node: Node, previousSibling: Node | undefined) { - if (stripInternal && node) { - node = getParseTreeNode(node); - const text = currentSourceFile.text; - const commentRanges = previousSibling - ? concatenate( - // to handle - // ... parameters, /* @internal */ - // public param: string - getTrailingCommentRanges(text, skipTrivia(text, previousSibling.end + 1, /* stopAfterLineBreak */ false, /* stopAtComments */ true)), - getLeadingCommentRanges(text, node.pos) - ) - : getTrailingCommentRanges(text, skipTrivia(text, node.pos, /* stopAfterLineBreak */ false, /* stopAtComments */ true)); - return commentRanges && commentRanges.length && hasInternalAnnotation(last(commentRanges)); - } - return false; - } - function isScopeMarker(node: Node) { return isExportAssignment(node) || isExportDeclaration(node); } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 6b9e493ad4e22..59ae825a8dc80 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -8236,6 +8236,7 @@ declare namespace ts.server { */ type ProjectRoot = ScriptInfo | NormalizedPath; abstract class Project implements LanguageServiceHost, ModuleResolutionHost { + readonly projectName: string; readonly projectKind: ProjectKind; readonly projectService: ProjectService; private documentRegistry;