-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(42765): require should not work in ts files (#42792)
* add failing test * fix(42765): require should not work in ts files
- Loading branch information
Showing
5 changed files
with
143 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//// [tests/cases/compiler/resolveNameWithNamspace.ts] //// | ||
|
||
//// [node.d.ts] | ||
declare function require(moduleName: string): any; | ||
|
||
declare module "assert" { | ||
export function equal(actual: any, expected: any, message?: string | Error): void; | ||
} | ||
|
||
//// [ns.ts] | ||
/// <reference path="node.d.ts"/> | ||
namespace myAssert { | ||
export type cool = 'cool' | ||
} | ||
var myAssert = require('assert') | ||
|
||
//// [app.js] | ||
exports.equal = myAssert.equal | ||
exports.equal() | ||
|
||
//// [ns.js] | ||
/// <reference path="node.d.ts"/> | ||
var myAssert = require('assert'); | ||
//// [app.js] | ||
exports.equal = myAssert.equal; | ||
exports.equal(); |
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,40 @@ | ||
=== tests/cases/compiler/node.d.ts === | ||
declare function require(moduleName: string): any; | ||
>require : Symbol(require, Decl(node.d.ts, 0, 0)) | ||
>moduleName : Symbol(moduleName, Decl(node.d.ts, 0, 25)) | ||
|
||
declare module "assert" { | ||
>"assert" : Symbol("assert", Decl(node.d.ts, 0, 50)) | ||
|
||
export function equal(actual: any, expected: any, message?: string | Error): void; | ||
>equal : Symbol(equal, Decl(node.d.ts, 2, 25)) | ||
>actual : Symbol(actual, Decl(node.d.ts, 3, 26)) | ||
>expected : Symbol(expected, Decl(node.d.ts, 3, 38)) | ||
>message : Symbol(message, Decl(node.d.ts, 3, 53)) | ||
>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) | ||
} | ||
|
||
=== tests/cases/compiler/ns.ts === | ||
/// <reference path="node.d.ts"/> | ||
namespace myAssert { | ||
>myAssert : Symbol(myAssert, Decl(ns.ts, 0, 0), Decl(ns.ts, 4, 3)) | ||
|
||
export type cool = 'cool' | ||
>cool : Symbol(cool, Decl(ns.ts, 1, 20)) | ||
} | ||
var myAssert = require('assert') | ||
>myAssert : Symbol(myAssert, Decl(ns.ts, 0, 0), Decl(ns.ts, 4, 3)) | ||
>require : Symbol(require, Decl(node.d.ts, 0, 0)) | ||
|
||
=== tests/cases/compiler/app.js === | ||
exports.equal = myAssert.equal | ||
>exports.equal : Symbol(equal, Decl(app.js, 0, 0)) | ||
>exports : Symbol(equal, Decl(app.js, 0, 0)) | ||
>equal : Symbol(equal, Decl(app.js, 0, 0)) | ||
>myAssert : Symbol(myAssert, Decl(ns.ts, 0, 0), Decl(ns.ts, 4, 3)) | ||
|
||
exports.equal() | ||
>exports.equal : Symbol(equal, Decl(app.js, 0, 0)) | ||
>exports : Symbol("tests/cases/compiler/app", Decl(app.js, 0, 0)) | ||
>equal : Symbol(equal, Decl(app.js, 0, 0)) | ||
|
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,43 @@ | ||
=== tests/cases/compiler/node.d.ts === | ||
declare function require(moduleName: string): any; | ||
>require : (moduleName: string) => any | ||
>moduleName : string | ||
|
||
declare module "assert" { | ||
>"assert" : typeof import("assert") | ||
|
||
export function equal(actual: any, expected: any, message?: string | Error): void; | ||
>equal : (actual: any, expected: any, message?: string | Error) => void | ||
>actual : any | ||
>expected : any | ||
>message : string | Error | ||
} | ||
|
||
=== tests/cases/compiler/ns.ts === | ||
/// <reference path="node.d.ts"/> | ||
namespace myAssert { | ||
export type cool = 'cool' | ||
>cool : "cool" | ||
} | ||
var myAssert = require('assert') | ||
>myAssert : any | ||
>require('assert') : any | ||
>require : (moduleName: string) => any | ||
>'assert' : "assert" | ||
|
||
=== tests/cases/compiler/app.js === | ||
exports.equal = myAssert.equal | ||
>exports.equal = myAssert.equal : any | ||
>exports.equal : error | ||
>exports : typeof import("tests/cases/compiler/app") | ||
>equal : any | ||
>myAssert.equal : any | ||
>myAssert : any | ||
>equal : any | ||
|
||
exports.equal() | ||
>exports.equal() : error | ||
>exports.equal : error | ||
>exports : typeof import("tests/cases/compiler/app") | ||
>equal : any | ||
|
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,21 @@ | ||
// @module: commonjs | ||
// @allowJs: true | ||
// @outDir: ./out/ | ||
|
||
// @filename: node.d.ts | ||
declare function require(moduleName: string): any; | ||
|
||
declare module "assert" { | ||
export function equal(actual: any, expected: any, message?: string | Error): void; | ||
} | ||
|
||
// @filename: ns.ts | ||
/// <reference path="node.d.ts"/> | ||
namespace myAssert { | ||
export type cool = 'cool' | ||
} | ||
var myAssert = require('assert') | ||
|
||
// @filename: app.js | ||
exports.equal = myAssert.equal | ||
exports.equal() |