| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 77555d8 commit 18f01dd
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,7 @@ const { | |||
| 58 | 58 | PromiseRace, | |
| 59 | 59 | RegExp, | |
| 60 | 60 | Set, | |
| 61 | + StringPrototypeIncludes, | ||
| 61 | 62 | Symbol, | |
| 62 | 63 | WeakSet, | |
| 63 | 64 | } = primordials; | |
@@ -549,6 +550,14 @@ function REPLServer(prompt, | |||
| 549 | 550 | e.stack = e.stack | |
| 550 | 551 | .replace(/^REPL\d+:\d+\r?\n/, '') | |
| 551 | 552 | .replace(/^\s+at\s.*\n?/gm, ''); | |
| 553 | + const importErrorStr = 'Cannot use import statement outside a ' + | ||
| 554 | + 'module'; | ||
| 555 | + if (StringPrototypeIncludes(e.message, importErrorStr)) { | ||
| 556 | + e.message = 'Cannot use import statement inside the Node.js ' + | ||
| 557 | + 'repl, alternatively use dynamic import'; | ||
| 558 | + e.stack = e.stack.replace(/SyntaxError:.*\n/, | ||
| 559 | + `SyntaxError: ${e.message}\n`); | ||
| 560 | + } | ||
| 552 | 561 | } else if (self.replMode === exports.REPL_MODE_STRICT) { | |
| 553 | 562 | e.stack = e.stack.replace(/(\s+at\s+REPL\d+:)(\d+)/, | |
| 554 | 563 | (_, pre, line) => pre + (line - 1)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -805,6 +805,16 @@ const tcpTests = [ | |||
| 805 | 805 | { | |
| 806 | 806 | send: `require(${JSON.stringify(moduleFilename)}).number`, | |
| 807 | 807 | expect: '42' | |
| 808 | + }, | ||
| 809 | + { | ||
| 810 | + send: 'import comeOn from \'fhqwhgads\'', | ||
| 811 | + expect: [ | ||
| 812 | + kSource, | ||
| 813 | + kArrow, | ||
| 814 | + '', | ||
| 815 | + 'Uncaught:', | ||
| 816 | + /^SyntaxError: .* dynamic import/ | ||
| 817 | + ] | ||
| 808 | 818 | } | |
| 809 | 819 | ]; | |
| 810 | 820 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments