| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ba47632 commit 0867ab7
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ const { | |||
| 8 | 8 | SafePromise, | |
| 9 | 9 | StringPrototypeIncludes, | |
| 10 | 10 | StringPrototypeMatch, | |
| 11 | + StringPrototypeReplace, | ||
| 11 | 12 | StringPrototypeSplit, | |
| 12 | 13 | } = primordials; | |
| 13 | 14 | ||
@@ -108,13 +109,14 @@ class ModuleJob { | |||
| 108 | 109 | if (format === 'commonjs') { | |
| 109 | 110 | const importStatement = splitStack[1]; | |
| 110 | 111 | const namedImports = StringPrototypeMatch(importStatement, /{.*}/)[0]; | |
| 112 | + const destructuringAssignment = StringPrototypeReplace(namedImports, /\s+as\s+/g, ': '); | ||
| 111 | 113 | e.message = `The requested module '${childSpecifier}' is expected ` + | |
| 112 | 114 | 'to be of type CommonJS, which does not support named exports. ' + | |
| 113 | 115 | 'CommonJS modules can be imported by importing the default ' + | |
| 114 | 116 | 'export.\n' + | |
| 115 | 117 | 'For example:\n' + | |
| 116 | 118 | `import pkg from '${childSpecifier}';\n` + | |
| 117 | - `const ${namedImports} = pkg;`; | ||
| 119 | + `const ${destructuringAssignment} = pkg;`; | ||
| 118 | 120 | const newStack = StringPrototypeSplit(e.stack, '\n'); | |
| 119 | 121 | newStack[3] = `SyntaxError: ${e.message}`; | |
| 120 | 122 | e.stack = ArrayPrototypeJoin(newStack, '\n'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,13 @@ const expectedRelative = 'The requested module \'./fail.cjs\' is expected to ' + | |||
| 10 | 10 | 'import pkg from \'./fail.cjs\';\n' + | |
| 11 | 11 | 'const { comeOn } = pkg;'; | |
| 12 | 12 | ||
| 13 | + const expectedRenamed = 'The requested module \'./fail.cjs\' is expected to ' + | ||
| 14 | + 'be of type CommonJS, which does not support named exports. CommonJS ' + | ||
| 15 | + 'modules can be imported by importing the default export.\n' + | ||
| 16 | + 'For example:\n' + | ||
| 17 | + 'import pkg from \'./fail.cjs\';\n' + | ||
| 18 | + 'const { comeOn: comeOnRenamed } = pkg;'; | ||
| 19 | + | ||
| 13 | 20 | const expectedPackageHack = 'The requested module \'./json-hack/fail.js\' is ' + | |
| 14 | 21 | 'expected to be of type CommonJS, which does not support named exports. ' + | |
| 15 | 22 | 'CommonJS modules can be imported by importing the default export.\n' + | |
@@ -38,6 +45,13 @@ rejects(async () => { | |||
| 38 | 45 | message: expectedRelative | |
| 39 | 46 | }, 'should support relative specifiers with double quotes'); | |
| 40 | 47 | ||
| 48 | + rejects(async () => { | ||
| 49 | + await import(`${fixtureBase}/renamed-import.mjs`); | ||
| 50 | + }, { | ||
| 51 | + name: 'SyntaxError', | ||
| 52 | + message: expectedRenamed | ||
| 53 | + }, 'should correctly format named imports with renames'); | ||
| 54 | + | ||
| 41 | 55 | rejects(async () => { | |
| 42 | 56 | await import(`${fixtureBase}/json-hack.mjs`); | |
| 43 | 57 | }, { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + import { comeOn as comeOnRenamed } from "./fail.cjs" | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments