Skip to content

Commit

Permalink
simptify StripInternal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Apr 25, 2018
1 parent 8aadbd1 commit e677be2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
12 changes: 6 additions & 6 deletions src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, U>(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<T, U>(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);
Expand Down Expand Up @@ -736,8 +736,8 @@ namespace ts {
return iterateCommentRanges(/*reduce*/ false, text, pos, /*trailing*/ true, cb, state);
}

export function reduceEachLeadingCommentRange<T, U>(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<T, U>(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<T, U>(text: string, pos: number, cb: (pos: number, end: number, kind: CommentKind, hasTrailingNewLine: boolean, state: T, memo: U) => U, state: T, initial: U) {
Expand All @@ -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 {
Expand Down
15 changes: 4 additions & 11 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 2 additions & 6 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,8 @@ namespace ts {
&& (<ExpressionStatement>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) {
Expand Down

0 comments on commit e677be2

Please sign in to comment.