Improve parse for module sources #177
Merged
+507
−112
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.
This changes the parsing behavior of
DeclarationReference.parse
when parsing module sources and components:@
is not allowed in an un-quoted symbol component (i.e.@a
is not valid, but"@a"
is).@microsoft/rush-stack-compiler-3.5
will throw, as@
and5
are not valid identifiers and there is no trailing!
token.@
and treat it as a path, I believe it is better to be unambiguous. An@
is only allowed if we scan ahead and find a!
token.@microsoft/rush-stack-compiler-3.5!
will parse with a module source of@microsoft/rush-stack-compiler-3.5
as we will scan ahead and find the!
token.!
token in its text, the module source must be quoted (i.e.a!b!c
is an error, but"a!b"!c
is valid, with"a!b"
as the module source).Also there are a few additional changes to make the API easier to use:
DeclarationReference.isWellFormedModuleSourceString(text)
- Returns whether the text is a valid module source.DeclarationReference.escapeModuleSourceString(text)
- Surrounds a module source in quotemarks if it is not well-formed.DeclarationReference.unescapeModuleSourceString(text)
- Unquotes a module source if necessary.ModuleSource#escapedPath
- Preserves the module source as written (including quotemarks). This was previously the value forModuleSource#path
ModuleSource#path
- The unescaped module source.ModuleSource#scopeName
- The scope name for the module, if it has one. Includes the leading@
.ModuleSource#unscopedPackageName
- The package name excluding the scope name.ModuleSource.fromScopedPacage(scopeName, unscopedPackageName, importPath)
- Create a module source from a scope.I've also added several suites of tests for various behaviors.
Fixes #174