-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
repl: attach location info to syntax errors #4013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Currently, when a file with a syntax error is imported in the REPL, no information is provided on the error's location. This commit adds the error's location to the stack trace. Refs: #2762 Refs: #3411 Refs: #3784 PR-URL: #4013 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const path = require('path'); | ||
| const repl = require('repl'); | ||
| const util = require('util'); | ||
| let found = false; | ||
|
|
||
| process.on('exit', () => { | ||
| assert.strictEqual(found, true); | ||
| }); | ||
|
|
||
| // A stream to push an array into a REPL | ||
| function ArrayStream() { | ||
| this.run = function(data) { | ||
| data.forEach(line => { | ||
| this.emit('data', line + '\n'); | ||
| }); | ||
| }; | ||
| } | ||
| util.inherits(ArrayStream, require('stream').Stream); | ||
| ArrayStream.prototype.readable = true; | ||
| ArrayStream.prototype.writable = true; | ||
| ArrayStream.prototype.resume = function() {}; | ||
| ArrayStream.prototype.write = function(output) { | ||
| if (/var foo bar;/.test(output)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have to assert the result in process's exit, simply
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| found = true; | ||
| }; | ||
|
|
||
| const putIn = new ArrayStream(); | ||
| const testMe = repl.start('', putIn); | ||
| let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax'); | ||
|
|
||
| if (common.isWindows) | ||
| file = file.replace(/\\/g, '\\\\'); | ||
|
|
||
| putIn.run(['.clear']); | ||
| putIn.run([`require('${file}');`]); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use
common.mustCallhere to make sure that this is called.