A RetroSearch Logo

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

Search Query:

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

fix extensionless typescript in cjs loader · nodejs/node@ab1f0b4 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+32

-12

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+32

-12

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

@@ -653,9 +653,13 @@ function getDefaultExtensions() {

653 653

let extensions = ObjectKeys(Module._extensions);

654 654

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

655 655

if (tsEnabled) {

656 +

// remove .ts and .cts from the default extensions

657 +

// to avoid extensionless require of .ts and .cts files.

658 +

// it behaves similarly to how .mjs is handled when --experimental-require-module

659 +

// is enabled.

656 660

extensions = ArrayPrototypeFilter(extensions, (ext) =>

657 -

ext !== '.ts' || Module._extensions['.ts'] !== loadTS ||

658 -

ext !== '.cts' || Module._extensions['.ts'] !== loadCTS,

661 +

(ext !== '.ts' || Module._extensions['.ts'] !== loadTS) &&

662 +

(ext !== '.cts' || Module._extensions['.cts'] !== loadCTS),

659 663

);

660 664

}

661 665 Original file line number Diff line number Diff line change

@@ -18,8 +18,6 @@ test('require a .ts file with explicit extension succeeds', async () => {

18 18

strictEqual(result.code, 0);

19 19

});

20 20 21 -

// TODO(marco-ippolito) This test should fail because extensionless require

22 -

// but it's behaving like a .js file

23 21

test('eval require a .ts file with implicit extension fails', async () => {

24 22

const result = await spawnPromisified(process.execPath, [

25 23

'--experimental-strip-types',

@@ -30,23 +28,36 @@ test('eval require a .ts file with implicit extension fails', async () => {

30 28

cwd: fixtures.path('typescript/ts'),

31 29

});

32 30 33 -

strictEqual(result.stderr, '');

34 -

match(result.stdout, /Hello, TypeScript!/);

35 -

strictEqual(result.code, 0);

31 +

strictEqual(result.stdout, '');

32 +

match(result.stderr, /Error: Cannot find module/);

33 +

strictEqual(result.code, 1);

34 +

});

35 + 36 +

test('eval require a .cts file with implicit extension fails', async () => {

37 +

const result = await spawnPromisified(process.execPath, [

38 +

'--experimental-strip-types',

39 +

'--eval',

40 +

'require("./test-cts-typescript")',

41 +

'--no-warnings',

42 +

], {

43 +

cwd: fixtures.path('typescript/ts'),

44 +

});

45 + 46 +

strictEqual(result.stdout, '');

47 +

match(result.stderr, /Error: Cannot find module/);

48 +

strictEqual(result.code, 1);

36 49

});

37 50 38 -

// TODO(marco-ippolito) This test should fail because extensionless require

39 -

// but it's behaving like a .js file

40 51

test('require a .ts file with implicit extension fails', async () => {

41 52

const result = await spawnPromisified(process.execPath, [

42 53

'--experimental-strip-types',

43 54

'--no-warnings',

44 55

fixtures.path('typescript/cts/test-extensionless-require.ts'),

45 56

]);

46 57 47 -

strictEqual(result.stderr, '');

48 -

match(result.stdout, /Hello, TypeScript!/);

49 -

strictEqual(result.code, 0);

58 +

strictEqual(result.stdout, '');

59 +

match(result.stderr, /Error: Cannot find module/);

60 +

strictEqual(result.code, 1);

50 61

});

51 62 52 63

test('expect failure of an .mts file with CommonJS syntax', async () => {

Original file line number Diff line number Diff line change

@@ -0,0 +1,5 @@

1 +

const str: string = "Hello, TypeScript!";

2 +

interface Foo {

3 +

bar: string;

4 +

}

5 +

console.log(str);

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