@ms-cloudpack/path-string-parsing 1.2.5 → 1.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/makeUrl.d.ts.map +1 -1
- package/lib/makeUrl.js.map +1 -1
- package/lib/parseNamedImports.d.ts +9 -2
- package/lib/parseNamedImports.d.ts.map +1 -1
- package/lib/parseNamedImports.js +42 -14
- package/lib/parseNamedImports.js.map +1 -1
- package/package.json +1 -1
- package/lib/tsdoc-metadata.json +0 -11
package/lib/makeUrl.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeUrl.d.ts","sourceRoot":"","sources":["../src/makeUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,
|
|
1
|
+
{"version":3,"file":"makeUrl.d.ts","sourceRoot":"","sources":["../src/makeUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,CAO/D"}
|
package/lib/makeUrl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeUrl.js","sourceRoot":"","sources":["../src/makeUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,IAAmB;IACxD,IAAI,CAAC;QACH,mFAAmF;QACnF,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,aAAa,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC;AACH,CAAC","sourcesContent":["/**\n * Attempt to create a URL object from a string, and throw an informative error if it fails.\n * (The URL constructor throws a very generic error.)\n */\nexport function makeUrl(input: string, base?: string | URL) {\n try {\n // eslint-disable-next-line no-restricted-syntax -- this is the function definition\n return new URL(input, base);\n } catch {\n throw new Error(`Invalid URL: \"${input}\", base: \"${base || ''}\"`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"makeUrl.js","sourceRoot":"","sources":["../src/makeUrl.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,IAAmB;IACxD,IAAI,CAAC;QACH,mFAAmF;QACnF,OAAO,IAAI,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CAAC,iBAAiB,KAAK,aAAa,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;IACpE,CAAC;AACH,CAAC","sourcesContent":["/**\n * Attempt to create a URL object from a string, and throw an informative error if it fails.\n * (The URL constructor throws a very generic error.)\n */\nexport function makeUrl(input: string, base?: string | URL): URL {\n try {\n // eslint-disable-next-line no-restricted-syntax -- this is the function definition\n return new URL(input, base);\n } catch {\n throw new Error(`Invalid URL: \"${input}\", base: \"${base || ''}\"`);\n }\n}\n"]}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parses a JS import/export statement (from a path) into its component parts.
|
|
3
|
-
* Does NOT handle typescript (import/export type)
|
|
3
|
+
* Does NOT handle typescript (`import/export type`), imports not from paths, exports without paths,
|
|
4
|
+
* or anything that's not a syntactically valid import/export statement.
|
|
5
|
+
*
|
|
6
|
+
* The statement is expected to be copied verbatim from a source file, so there's a slight chance it
|
|
7
|
+
* could contain comments embedded in the middle. This will try to remove the comments, but
|
|
8
|
+
* accuracy is not guaranteed (especially for contrived scenarios like imports inside comments).
|
|
9
|
+
*
|
|
4
10
|
* @param importLine - The import string to parse.
|
|
5
|
-
* @returns A string array with the named imports, default and/or '*'
|
|
11
|
+
* @returns A string array with the named imports, `'default'` and/or `'*'`.
|
|
12
|
+
* This will return the original names, not the imported names.
|
|
6
13
|
*/
|
|
7
14
|
export declare function parseNamedImports(importLine: string): string[];
|
|
8
15
|
//# sourceMappingURL=parseNamedImports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseNamedImports.d.ts","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseNamedImports.d.ts","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA8C9D"}
|
package/lib/parseNamedImports.js
CHANGED
|
@@ -1,35 +1,63 @@
|
|
|
1
|
+
const namedImportRegex =
|
|
2
|
+
// 1: maybe name for default (imports only): import foo from "package"
|
|
3
|
+
// 2: maybe * part: import * as myModule from "package"
|
|
4
|
+
// note that these can be combined: import foo, * as myModule from "package"
|
|
5
|
+
// 3: maybe names: import { foo, bar } from "package"
|
|
6
|
+
// (can be combined with 1 but not 2)
|
|
7
|
+
// Matches of \s in the middle of the string are non-greedy to reduce potential backtracking.
|
|
8
|
+
// The { names } match is very crude (all possible characters in any order) to improve performance,
|
|
9
|
+
// since we know the input is syntactically valid and we'll actually match the names later.
|
|
10
|
+
// ( 1 ) ( 2 ) ( 3 ) from path
|
|
11
|
+
/^\s*[ie][mx]port\s*?([\w$]+)?\s*?,?\s*?(\*(?:\s*?as\s+?[\w$]+)?)?\s*?(?:\{([\w$\s,]*)\})?\s*from\s*["']/;
|
|
1
12
|
/**
|
|
2
13
|
* Parses a JS import/export statement (from a path) into its component parts.
|
|
3
|
-
* Does NOT handle typescript (import/export type)
|
|
14
|
+
* Does NOT handle typescript (`import/export type`), imports not from paths, exports without paths,
|
|
15
|
+
* or anything that's not a syntactically valid import/export statement.
|
|
16
|
+
*
|
|
17
|
+
* The statement is expected to be copied verbatim from a source file, so there's a slight chance it
|
|
18
|
+
* could contain comments embedded in the middle. This will try to remove the comments, but
|
|
19
|
+
* accuracy is not guaranteed (especially for contrived scenarios like imports inside comments).
|
|
20
|
+
*
|
|
4
21
|
* @param importLine - The import string to parse.
|
|
5
|
-
* @returns A string array with the named imports, default and/or '*'
|
|
22
|
+
* @returns A string array with the named imports, `'default'` and/or `'*'`.
|
|
23
|
+
* This will return the original names, not the imported names.
|
|
6
24
|
*/
|
|
7
25
|
export function parseNamedImports(importLine) {
|
|
8
|
-
|
|
9
|
-
// With some edits to catch export * from "package" and removing lots of unneeded groups.
|
|
10
|
-
// (This won't handle comments; if that's ever needed, we should use acorn for full parsing.)
|
|
11
|
-
const matches = importLine.match(
|
|
12
|
-
// 1 default 2 * 3 names 4 path
|
|
13
|
-
/^\s*(?:import|export)\s*(?=[\s*{])\s*((?:[$\w]+(?:\s+as\s+[$\w]+)?(?=\s*,\s*[{*]|\s+from))?)[\s,]*((?:\*\s*as\s+[$\w]+)?|\*)[\s,]*(?:\{\s*((?:[$\w]+(?:\s+as\s+[$\w]+)?\s*,?\s*)*)\})?\s*from\s*["']([^"']*)/);
|
|
14
|
-
// If no matches return empty array
|
|
26
|
+
let matches = importLine.match(namedImportRegex);
|
|
15
27
|
if (!matches) {
|
|
16
|
-
|
|
28
|
+
if (/^import\s*?["'][^"']*["']/.test(importLine)) {
|
|
29
|
+
// This is a side effect import, so return empty array.
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
// Maybe there are some embedded comments? Try removing them.
|
|
33
|
+
importLine = importLine
|
|
34
|
+
// Start by finding and removing the path to reduce chance of accidents.
|
|
35
|
+
.replace(/\bfrom\s*(["'])[^"']*["'].*/, 'from "removed"')
|
|
36
|
+
// Remove single-line and multi-line comments. This could behave badly in contrived
|
|
37
|
+
// nesting scenarios, but should be reliable for more common cases.
|
|
38
|
+
.replaceAll(/\/\/.*/g, '')
|
|
39
|
+
.replaceAll(/\/\*[\s\S]*?\*\//g, '');
|
|
40
|
+
// Try again
|
|
41
|
+
matches = importLine.match(namedImportRegex);
|
|
42
|
+
if (!matches) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
17
45
|
}
|
|
18
46
|
const names = [];
|
|
19
|
-
// Default export
|
|
20
47
|
if (matches[1]) {
|
|
48
|
+
// Default export
|
|
21
49
|
names.push('default');
|
|
22
50
|
}
|
|
23
|
-
// Imported or exported names
|
|
24
51
|
if (matches[3]) {
|
|
25
|
-
//
|
|
52
|
+
// Imported or exported names
|
|
53
|
+
// Clean out the whitespace, and get the original names not the aliases
|
|
26
54
|
const namedImports = matches[3].matchAll(/([\w$]+)(?:\s+as\s+[\w$]+,?)?/g);
|
|
27
55
|
for (const namedImport of namedImports) {
|
|
28
56
|
names.push(namedImport[1]);
|
|
29
57
|
}
|
|
30
58
|
}
|
|
31
|
-
// If there is a namespace export, push it to the names array
|
|
32
59
|
if (matches[2]) {
|
|
60
|
+
// All names
|
|
33
61
|
names.push('*');
|
|
34
62
|
}
|
|
35
63
|
return names;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseNamedImports.js","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parseNamedImports.js","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"AAAA,MAAM,gBAAgB;AACpB,uEAAuE;AACvE,iFAAiF;AACjF,sFAAsF;AACtF,gFAAgF;AAChF,wCAAwC;AACxC,6FAA6F;AAC7F,mGAAmG;AACnG,2FAA2F;AAC3F,wGAAwG;AACxG,yGAAyG,CAAC;AAE5G;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,IAAI,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAEjD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,IAAI,2BAA2B,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACjD,uDAAuD;YACvD,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,6DAA6D;QAC7D,UAAU,GAAG,UAAU;YACrB,wEAAwE;aACvE,OAAO,CAAC,6BAA6B,EAAE,gBAAgB,CAAC;YACzD,mFAAmF;YACnF,mEAAmE;aAClE,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC;aACzB,UAAU,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC;QAEvC,YAAY;QACZ,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAC7C,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACf,iBAAiB;QACjB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACf,6BAA6B;QAC7B,uEAAuE;QACvE,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,gCAAgC,CAAC,CAAC;QAC3E,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACvC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACf,YAAY;QACZ,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["const namedImportRegex =\n // 1: maybe name for default (imports only): import foo from \"package\"\n // 2: maybe * part: import * as myModule from \"package\"\n // note that these can be combined: import foo, * as myModule from \"package\"\n // 3: maybe names: import { foo, bar } from \"package\"\n // (can be combined with 1 but not 2)\n // Matches of \\s in the middle of the string are non-greedy to reduce potential backtracking.\n // The { names } match is very crude (all possible characters in any order) to improve performance,\n // since we know the input is syntactically valid and we'll actually match the names later.\n // ( 1 ) ( 2 ) ( 3 ) from path\n /^\\s*[ie][mx]port\\s*?([\\w$]+)?\\s*?,?\\s*?(\\*(?:\\s*?as\\s+?[\\w$]+)?)?\\s*?(?:\\{([\\w$\\s,]*)\\})?\\s*from\\s*[\"']/;\n\n/**\n * Parses a JS import/export statement (from a path) into its component parts.\n * Does NOT handle typescript (`import/export type`), imports not from paths, exports without paths,\n * or anything that's not a syntactically valid import/export statement.\n *\n * The statement is expected to be copied verbatim from a source file, so there's a slight chance it\n * could contain comments embedded in the middle. This will try to remove the comments, but\n * accuracy is not guaranteed (especially for contrived scenarios like imports inside comments).\n *\n * @param importLine - The import string to parse.\n * @returns A string array with the named imports, `'default'` and/or `'*'`.\n * This will return the original names, not the imported names.\n */\nexport function parseNamedImports(importLine: string): string[] {\n let matches = importLine.match(namedImportRegex);\n\n if (!matches) {\n if (/^import\\s*?[\"'][^\"']*[\"']/.test(importLine)) {\n // This is a side effect import, so return empty array.\n return [];\n }\n\n // Maybe there are some embedded comments? Try removing them.\n importLine = importLine\n // Start by finding and removing the path to reduce chance of accidents.\n .replace(/\\bfrom\\s*([\"'])[^\"']*[\"'].*/, 'from \"removed\"')\n // Remove single-line and multi-line comments. This could behave badly in contrived\n // nesting scenarios, but should be reliable for more common cases.\n .replaceAll(/\\/\\/.*/g, '')\n .replaceAll(/\\/\\*[\\s\\S]*?\\*\\//g, '');\n\n // Try again\n matches = importLine.match(namedImportRegex);\n if (!matches) {\n return [];\n }\n }\n\n const names: string[] = [];\n if (matches[1]) {\n // Default export\n names.push('default');\n }\n\n if (matches[3]) {\n // Imported or exported names\n // Clean out the whitespace, and get the original names not the aliases\n const namedImports = matches[3].matchAll(/([\\w$]+)(?:\\s+as\\s+[\\w$]+,?)?/g);\n for (const namedImport of namedImports) {\n names.push(namedImport[1]);\n }\n }\n\n if (matches[2]) {\n // All names\n names.push('*');\n }\n\n return names;\n}\n"]}
|
package/package.json
CHANGED
package/lib/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.47.11"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|