A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nodejs/node/commit/c1023284c3 below:

add typescript support to STDIN eval · nodejs/node@c102328 · GitHub

File tree Expand file treeCollapse file tree 6 files changed

+266

-9

lines changed

Filter options

Expand file treeCollapse file tree 6 files changed

+266

-9

lines changed Original file line number Diff line number Diff line change

@@ -156,10 +156,10 @@ import { fn, FnParams } from './fn.ts';

156 156 157 157

### Non-file forms of input

158 158 159 -

Type stripping can be enabled for `--eval`. The module system

159 +

Type stripping can be enabled for `--eval` and STDIN. The module system

160 160

will be determined by `--input-type`, as it is for JavaScript.

161 161 162 -

TypeScript syntax is unsupported in the REPL, STDIN input, `--print`, `--check`, and

162 +

TypeScript syntax is unsupported in the REPL, `--check`, and

163 163

`inspect`.

164 164 165 165

### Source maps

Original file line number Diff line number Diff line change

@@ -11,6 +11,9 @@ const { getOptionValue } = require('internal/options');

11 11 12 12

const {

13 13

evalModuleEntryPoint,

14 +

evalTypeScript,

15 +

parseAndEvalCommonjsTypeScript,

16 +

parseAndEvalModuleTypeScript,

14 17

evalScript,

15 18

readStdin,

16 19

} = require('internal/process/execution');

@@ -25,13 +28,30 @@ readStdin((code) => {

25 28 26 29

const print = getOptionValue('--print');

27 30

const shouldLoadESM = getOptionValue('--import').length > 0;

28 -

if (getOptionValue('--input-type') === 'module') {

31 +

const inputType = getOptionValue('--input-type');

32 +

const tsEnabled = getOptionValue('--experimental-strip-types');

33 +

if (inputType === 'module') {

29 34

evalModuleEntryPoint(code, print);

35 +

} else if (inputType === 'module-typescript' && tsEnabled) {

36 +

parseAndEvalModuleTypeScript(code, print);

30 37

} else {

31 -

evalScript('[stdin]',

32 -

code,

33 -

getOptionValue('--inspect-brk'),

34 -

print,

35 -

shouldLoadESM);

38 + 39 +

let evalFunction;

40 +

if (inputType === 'commonjs') {

41 +

evalFunction = evalScript;

42 +

} else if (inputType === 'commonjs-typescript' && tsEnabled) {

43 +

evalFunction = parseAndEvalCommonjsTypeScript;

44 +

} else if (tsEnabled) {

45 +

evalFunction = evalTypeScript;

46 +

} else {

47 +

// Default to commonjs.

48 +

evalFunction = evalScript;

49 +

}

50 + 51 +

evalFunction('[stdin]',

52 +

code,

53 +

getOptionValue('--inspect-brk'),

54 +

print,

55 +

shouldLoadESM);

36 56

}

37 57

});

Original file line number Diff line number Diff line change

@@ -2,10 +2,17 @@

2 2

[stdin]:1

3 3

with(this){__filename}

4 4

^^^^

5 +

x The 'with' statement is not supported. All symbols in a 'with' block will have type 'any'.

6 +

,----

7 +

1 | with(this){__filename}

8 +

: ^^^^

9 +

`----

5 10 6 -

SyntaxError: Strict mode code may not include a with statement

7 11 12 +

Caused by:

13 +

failed to parse

8 14 15 +

SyntaxError: Strict mode code may not include a with statement

9 16 10 17 11 18 Original file line number Diff line number Diff line change

@@ -0,0 +1,38 @@

1 +

'use strict';

2 + 3 +

require('../../common');

4 + 5 +

const spawn = require('child_process').spawn;

6 + 7 +

function run(cmd, strict, cb) {

8 +

const args = ['--disable-warning=ExperimentalWarning'];

9 +

if (strict) args.push('--use_strict');

10 +

args.push('-p');

11 +

const child = spawn(process.execPath, args);

12 +

child.stdout.pipe(process.stdout);

13 +

child.stderr.pipe(process.stdout);

14 +

child.stdin.end(cmd);

15 +

child.on('close', cb);

16 +

}

17 + 18 +

const queue =

19 +

[

20 +

'enum Foo{};',

21 +

'throw new SyntaxError("hello")',

22 +

'const foo;',

23 +

'let x: number = 100;x;',

24 +

'const foo: string = 10;',

25 +

'function foo(){};foo<Number>(1);',

26 +

'interface Foo{};const foo;',

27 +

'function foo(){ await Promise.resolve(1)};',

28 +

];

29 + 30 +

function go() {

31 +

const c = queue.shift();

32 +

if (!c) return console.log('done');

33 +

run(c, false, function () {

34 +

run(c, true, go);

35 +

});

36 +

}

37 + 38 +

go();

Original file line number Diff line number Diff line change

@@ -0,0 +1,191 @@

1 +

[stdin]:1

2 +

enum Foo{};

3 +

^^^^

4 +

x TypeScript enum is not supported in strip-only mode

5 +

,----

6 +

1 | enum Foo{};

7 +

: ^^^^^^^^^^

8 +

`----

9 + 10 + 11 +

SyntaxError: Unexpected reserved word

12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 +

Node.js *

22 +

[stdin]:1

23 +

enum Foo{};

24 +

^^^^

25 +

x TypeScript enum is not supported in strip-only mode

26 +

,----

27 +

1 | enum Foo{};

28 +

: ^^^^^^^^^^

29 +

`----

30 + 31 + 32 +

SyntaxError: Unexpected reserved word

33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 +

Node.js *

43 +

[stdin]:1

44 +

throw new SyntaxError("hello")

45 +

^

46 + 47 +

SyntaxError: hello

48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 +

Node.js *

60 +

[stdin]:1

61 +

throw new SyntaxError("hello")

62 +

^

63 + 64 +

SyntaxError: hello

65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 +

Node.js *

77 +

[stdin]:1

78 +

const foo;

79 +

^^^

80 + 81 +

SyntaxError: Missing initializer in const declaration

82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 +

Node.js *

92 +

[stdin]:1

93 +

const foo;

94 +

^^^

95 + 96 +

SyntaxError: Missing initializer in const declaration

97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 +

Node.js *

107 +

100

108 +

100

109 +

undefined

110 +

undefined

111 +

false

112 +

false

113 +

[stdin]:1

114 +

;const foo;

115 +

^^^

116 + 117 +

SyntaxError: Missing initializer in const declaration

118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 127 +

Node.js *

128 +

[stdin]:1

129 +

;const foo;

130 +

^^^

131 + 132 +

SyntaxError: Missing initializer in const declaration

133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 +

Node.js *

143 +

[stdin]:1

144 +

function foo(){ await Promise.resolve(1)};

145 +

^^^^^

146 +

x await isn't allowed in non-async function

147 +

,----

148 +

1 | function foo(){ await Promise.resolve(1)};

149 +

: ^^^^^^^

150 +

`----

151 + 152 + 153 +

Caused by:

154 +

failed to parse

155 + 156 +

SyntaxError: await is only valid in async functions and the top level bodies of modules

157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 +

Node.js *

167 +

[stdin]:1

168 +

function foo(){ await Promise.resolve(1)};

169 +

^^^^^

170 +

x await isn't allowed in non-async function

171 +

,----

172 +

1 | function foo(){ await Promise.resolve(1)};

173 +

: ^^^^^^^

174 +

`----

175 + 176 + 177 +

Caused by:

178 +

failed to parse

179 + 180 +

SyntaxError: await is only valid in async functions and the top level bodies of modules

181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 +

Node.js *

191 +

done

Original file line number Diff line number Diff line change

@@ -24,6 +24,7 @@ describe('eval output', { concurrency: true }, () => {

24 24

const tests = [

25 25

{ name: 'eval/eval_messages.js' },

26 26

{ name: 'eval/stdin_messages.js' },

27 +

{ name: 'eval/stdin_typescript.js' },

27 28

];

28 29 29 30

for (const { name } of tests) {

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4