-
Notifications
You must be signed in to change notification settings - Fork 663
[api-extractor] ApiItem.name is now quoted when it contains invalid identifier characters #1410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
93526ff
Add some test cases for quoted identifiers and ECMAScript symbols
octogonz 5b53abb
Make AstSymbol.localName more rigorous
octogonz 2f80065
rush change
octogonz 4027d35
Fix a regression for the defaultExportOfEntryPoint scenario
octogonz 7601737
Prevent characters such as `"` and `[` from being used in filenames
octogonz 264d732
rush rebuild
octogonz 286485c
rush change
octogonz db76045
PR feedback
octogonz e67b37a
PR feedback: Clarify how well-known symbols get decoded
octogonz 793f139
PR feedback
octogonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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,51 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. | ||
| // See LICENSE in the project root for license information. | ||
|
|
||
| /** | ||
| * Helpers for validating various text string formats. | ||
| */ | ||
| export class StringChecks { | ||
| // Note: In addition to letters, numbers, underscores, and dollar signs, modern ECMAScript | ||
| // also allows Unicode categories such as letters, combining marks, digits, and connector punctuation. | ||
| // These are mostly supported in all environments except IE11, so if someone wants it, we would accept | ||
| // a PR to allow them (although the test surface might be somewhat large). | ||
| private static readonly _identifierBadCharRegExp: RegExp = /[^a-z0-9_$]/i; | ||
|
|
||
| // Identifiers most not start with a number. | ||
| private static readonly _identifierNumberStartRegExp: RegExp = /^[0-9]/; | ||
|
|
||
| /** | ||
| * Tests whether the input string is safe to use as an ECMAScript identifier without quotes. | ||
| * | ||
| * @remarks | ||
| * For example: | ||
| * | ||
| * ```ts | ||
| * class X { | ||
| * public okay: number = 1; | ||
| * public "not okay!": number = 2; | ||
| * } | ||
| * ``` | ||
| * | ||
| * A precise check is extremely complicated and highly dependent on the ECMAScript standard version | ||
| * and how faithfully the interpreter implements it. To keep things simple, `isValidUnquotedIdentifier()` | ||
| * conservatively checks for basic alphanumeric identifiers and returns false otherwise. | ||
| * | ||
| * Based on `StringChecks.explainIfInvalidUnquotedIdentifier()` from TSDoc. | ||
| */ | ||
| public static isSafeUnquotedMemberIdentifier(identifier: string): boolean { | ||
| if (identifier.length === 0) { | ||
| return false; // cannot be empty | ||
| } | ||
|
|
||
| if (StringChecks._identifierBadCharRegExp.test(identifier)) { | ||
| return false; // cannot contain bad characters | ||
| } | ||
|
|
||
| if (StringChecks._identifierNumberStartRegExp.test(identifier)) { | ||
| return false; // cannot start with a number | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.