FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix stripInternal handling of unrelated leading comments by splincode · Pull Request #64626 · microsoft/TypeScript · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (2) .js  (1) .ts  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 3 additions & 1 deletion tsc/internal/parser/parser.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,7 @@ func (p *Parser) parseTypeParameters() *ast.NodeList {

func (p *Parser) parseTypeParameter() *ast.Node {
pos := p.nodePos()
jsdoc := p.jsdocScannerInfo()
modifiers := p.parseModifiersEx(false /*allowDecorators*/, true /*permitConstAsModifier*/, false /*stopOnStartOfClassStaticBlock*/)
name := p.parseIdentifier()
var constraint *ast.TypeNode
Expand Down Expand Up @@ -3328,7 +3329,8 @@ func (p *Parser) parseTypeParameter() *ast.Node {
defaultType = p.parseType()
}
result := p.factory.NewTypeParameterDeclaration(modifiers, name, constraint, expression, defaultType)
return p.finishNode(result, pos)
p.withJSDoc(p.finishNode(result, pos), jsdoc)
return result
}

func (p *Parser) parseParameters(flags ParseFlags) *ast.NodeList {
Expand Down
27 changes: 23 additions & 4 deletions tsc/internal/transformers/declarations/transform.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,31 @@ func (tx *DeclarationTransformer) isInternalDeclaration(node *ast.Node, sourceFi
return false
}

for commentRange := range tx.getLeadingCommentRangesOfNode(parseTreeNode, sourceFile) {
if hasInternalAnnotation(commentRange, sourceFile) {
return true
for _, jsdoc := range parseTreeNode.JSDoc(sourceFile) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Addressed in 9b38ed2. Type parameters now attach JSDoc during parsing. The regression baseline confirms that the internal T is stripped while the public U remains. Thanks for catching this.

if tags := jsdoc.AsJSDoc().Tags; tags != nil {
for _, tag := range tags.Nodes {
if tag.TagName().Text() == "internal" {
return true
}
}
}
}
return false

// Preserve explicit non-JSDoc annotations on the nearest leading comment.
var lastComment ast.CommentRange
for commentRange := range tx.getLeadingCommentRangesOfNode(parseTreeNode, sourceFile) {
lastComment = commentRange
}
if lastComment.End() == 0 {
return false
}
comment := sourceFile.Text()[lastComment.Pos():lastComment.End()]
if strings.HasPrefix(comment, "/**") {
return false
}
comment = strings.TrimLeft(strings.TrimSuffix(comment[2:], "*/"), "* \t\r\n")
words := strings.Fields(comment)
return len(words) > 0 && words[0] == "@internal"
}

func (tx *DeclarationTransformer) getLeadingCommentRangesOfNode(node *ast.Node, sourceFile *ast.SourceFile) iter.Seq[ast.CommentRange] {
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
//// [tests/cases/compiler/stripInternalUnrelatedComments.ts] ////

//// [unrelated.ts]
export class Foo {
/**
* Should be stripped.
* @internal
*/
shouldBeStripped = 1;

// TODO: maybe make this @internal?

/**
* Public member.
*/
shouldNotBeStripped = 2;

// sure wish I had @internal support! anyway...
mentionedInLineComment = 3;

/* TODO: maybe make this @internal? */
mentionedInBlockComment = 4;

/** Public documentation mentioning `@internal`. */
mentionedInJSDocText = 5;

/** @internal */
internal = 6;

public = 7;

// @internal
internalLineAnnotation = 8;

/* @internal */
internalBlockAnnotation = 9;

/** @internal */
/** Additional documentation. */
internalWithMultipleJSDocComments = 10;

/** @internalOther */
publicWithOtherTag = 11;

// @internal
/** Public documentation. */
publicAfterUnrelatedAnnotation = 12;
}

/** @internal */
export const x = 1;

// TODO: maybe make this @internal?
/** Public declaration. */
export const publicValue = 2;

export class InternalTypeParameter<
/** @internal */ T = unknown,
U = unknown
> {}

export class PublicTypeParameters<
// TODO: maybe make this @internal?
/** Public type parameter. */
T = unknown,
/** Public documentation mentioning `@internal`. */
U = unknown
> {}

//// [unrelatedJs.js]
export class Bar {
/** @internal */
internal = 1;

// TODO: maybe make this @internal?
/** Public member. */
public = 2;

// sure wish I had @internal support! anyway...
mentionedInLineComment = 3;
}




//// [unrelated.d.ts]
export declare class Foo {
/**
* Public member.
*/
shouldNotBeStripped: number;
mentionedInLineComment: number;
mentionedInBlockComment: number;
/** Public documentation mentioning `@internal`. */
mentionedInJSDocText: number;
public: number;
/** @internalOther */
publicWithOtherTag: number;
/** Public documentation. */
publicAfterUnrelatedAnnotation: number;
}
/** Public declaration. */
export declare const publicValue = 2;
export declare class InternalTypeParameter<U = unknown> {
}
export declare class PublicTypeParameters<
/** Public type parameter. */
T = unknown,
/** Public documentation mentioning `@internal`. */
U = unknown> {
}
//// [unrelatedJs.d.ts]
export declare class Bar {
/** Public member. */
public: number;
mentionedInLineComment: number;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// @target: es2015
// @declaration: true
// @emitDeclarationOnly: true
// @stripInternal: true
// @allowJs: true
// @outDir: out
// @noTypesAndSymbols: true

// @filename: unrelated.ts
export class Foo {
/**
* Should be stripped.
* @internal
*/
shouldBeStripped = 1;

// TODO: maybe make this @internal?

/**
* Public member.
*/
shouldNotBeStripped = 2;

// sure wish I had @internal support! anyway...
mentionedInLineComment = 3;

/* TODO: maybe make this @internal? */
mentionedInBlockComment = 4;

/** Public documentation mentioning `@internal`. */
mentionedInJSDocText = 5;

/** @internal */
internal = 6;

public = 7;

// @internal
internalLineAnnotation = 8;

/* @internal */
internalBlockAnnotation = 9;

/** @internal */
/** Additional documentation. */
internalWithMultipleJSDocComments = 10;

/** @internalOther */
publicWithOtherTag = 11;

// @internal
/** Public documentation. */
publicAfterUnrelatedAnnotation = 12;
}

/** @internal */
export const x = 1;

// TODO: maybe make this @internal?
/** Public declaration. */
export const publicValue = 2;

export class InternalTypeParameter<
/** @internal */ T = unknown,
U = unknown
> {}

export class PublicTypeParameters<
// TODO: maybe make this @internal?
/** Public type parameter. */
T = unknown,
/** Public documentation mentioning `@internal`. */
U = unknown
> {}

// @filename: unrelatedJs.js
export class Bar {
/** @internal */
internal = 1;

// TODO: maybe make this @internal?
/** Public member. */
public = 2;

// sure wish I had @internal support! anyway...
mentionedInLineComment = 3;
}

Back | FazBrowse Home | New Git URL