-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add typescript support to STDIN eval
- Loading branch information
1 parent
3147ec2
commit 6bf1669
Showing
5 changed files
with
258 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
require('../../common'); | ||
|
||
const spawn = require('child_process').spawn; | ||
|
||
function run(cmd, strict, cb) { | ||
const args = ['--experimental-strip-types', '--disable-warning=ExperimentalWarning']; | ||
if (strict) args.push('--use_strict'); | ||
args.push('-p'); | ||
const child = spawn(process.execPath, args); | ||
child.stdout.pipe(process.stdout); | ||
child.stderr.pipe(process.stdout); | ||
child.stdin.end(cmd); | ||
child.on('close', cb); | ||
} | ||
|
||
const queue = | ||
[ | ||
'enum Foo{};', | ||
'throw new SyntaxError("hello")', | ||
'const foo;', | ||
'let x: number = 100;x;', | ||
'const foo: string = 10;', | ||
'function foo(){};foo<Number>(1);', | ||
'interface Foo{};const foo;', | ||
'function foo(){ await Promise.resolve(1)};', | ||
]; | ||
|
||
function go() { | ||
const c = queue.shift(); | ||
if (!c) return console.log('done'); | ||
run(c, false, function () { | ||
run(c, true, go); | ||
}); | ||
} | ||
|
||
go(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
[stdin]:1 | ||
enum Foo{}; | ||
^^^^ | ||
x TypeScript enum is not supported in strip-only mode | ||
,---- | ||
1 | enum Foo{}; | ||
: ^^^^^^^^^^ | ||
`---- | ||
|
||
|
||
SyntaxError: Unexpected reserved word | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
enum Foo{}; | ||
^^^^ | ||
x TypeScript enum is not supported in strip-only mode | ||
,---- | ||
1 | enum Foo{}; | ||
: ^^^^^^^^^^ | ||
`---- | ||
|
||
|
||
SyntaxError: Unexpected reserved word | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
throw new SyntaxError("hello") | ||
^ | ||
|
||
SyntaxError: hello | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
throw new SyntaxError("hello") | ||
^ | ||
|
||
SyntaxError: hello | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
const foo; | ||
^^^ | ||
|
||
SyntaxError: Missing initializer in const declaration | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
const foo; | ||
^^^ | ||
|
||
SyntaxError: Missing initializer in const declaration | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
100 | ||
100 | ||
undefined | ||
undefined | ||
false | ||
false | ||
[stdin]:1 | ||
;const foo; | ||
^^^ | ||
|
||
SyntaxError: Missing initializer in const declaration | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
;const foo; | ||
^^^ | ||
|
||
SyntaxError: Missing initializer in const declaration | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
function foo(){ await Promise.resolve(1)}; | ||
^^^^^ | ||
x await isn't allowed in non-async function | ||
,---- | ||
1 | function foo(){ await Promise.resolve(1)}; | ||
: ^^^^^^^ | ||
`---- | ||
|
||
|
||
Caused by: | ||
failed to parse | ||
|
||
SyntaxError: await is only valid in async functions and the top level bodies of modules | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
[stdin]:1 | ||
function foo(){ await Promise.resolve(1)}; | ||
^^^^^ | ||
x await isn't allowed in non-async function | ||
,---- | ||
1 | function foo(){ await Promise.resolve(1)}; | ||
: ^^^^^^^ | ||
`---- | ||
|
||
|
||
Caused by: | ||
failed to parse | ||
|
||
SyntaxError: await is only valid in async functions and the top level bodies of modules | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
Node.js * | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters