File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,13 +32,17 @@ describe("isRelativeSpecifier", () => {
3232 it ( "returns true for ./ and ../" , ( ) => {
3333 assert . ok ( isRelativeSpecifier ( "./foo" ) ) ;
3434 assert . ok ( isRelativeSpecifier ( "../bar" ) ) ;
35- assert . ok ( isRelativeSpecifier ( ".hidden" ) ) ;
3635 } ) ;
3736
3837 it ( "returns true for absolute paths starting with /" , ( ) => {
3938 assert . ok ( isRelativeSpecifier ( "/abs" ) ) ;
4039 } ) ;
4140
41+ it ( "returns false for dot-prefixed names without slash" , ( ) => {
42+ assert . ok ( ! isRelativeSpecifier ( ".hidden" ) ) ;
43+ assert . ok ( ! isRelativeSpecifier ( ".tsconfig.json" ) ) ;
44+ } ) ;
45+
4246 it ( "returns false for bare specifiers and URLs" , ( ) => {
4347 assert . ok ( ! isRelativeSpecifier ( "react" ) ) ;
4448 assert . ok ( ! isRelativeSpecifier ( "https://esm.sh/react" ) ) ;
Original file line number Diff line number Diff line change 11import ts from "typescript" ;
22
33export function isBareSpecifier ( specifier : string ) : boolean {
4- if ( specifier . match ( / ^ \. * \/ / ) ) return false ;
4+ if ( isRelativeSpecifier ( specifier ) ) return false ;
55
66 try {
77 new URL ( specifier ) ;
@@ -13,7 +13,11 @@ export function isBareSpecifier(specifier: string): boolean {
1313
1414/* Helper to check if a specifier is relative, note that it includes both relative paths and absolute paths */
1515export function isRelativeSpecifier ( specifier : string ) : boolean {
16- return specifier . startsWith ( "." ) || specifier . startsWith ( "/" ) ;
16+ return (
17+ specifier . startsWith ( "./" ) ||
18+ specifier . startsWith ( "../" ) ||
19+ specifier . startsWith ( "/" )
20+ ) ;
1721}
1822
1923export function collectSpecifiers ( sourceFile : ts . SourceFile ) : Set < string > {
You can’t perform that action at this time.
0 commit comments