Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0794861

Browse filesBrowse files
marco-ippolitoruyadorno
authored andcommitted
module: simplify ts under node_modules check
PR-URL: #55440 Backport-PR-URL: #56208 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent bcfe9c8 commit 0794861
Copy full SHA for 0794861

File tree

Expand file treeCollapse file tree

3 files changed

+6
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+6
-20
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+1-11Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ const { pathToFileURL, fileURLToPath, isURL } = require('internal/url');
125125
const {
126126
pendingDeprecate,
127127
emitExperimentalWarning,
128-
isUnderNodeModules,
129128
kEmptyObject,
130129
setOwnProperty,
131130
getLazy,
131+
isUnderNodeModules,
132132
isWindows,
133133
} = require('internal/util');
134134
const {
@@ -170,7 +170,6 @@ const {
170170
ERR_REQUIRE_CYCLE_MODULE,
171171
ERR_REQUIRE_ESM,
172172
ERR_UNKNOWN_BUILTIN_MODULE,
173-
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING,
174173
},
175174
setArrowMessage,
176175
} = require('internal/errors');
@@ -1348,9 +1347,6 @@ let emittedRequireModuleWarning = false;
13481347
function loadESMFromCJS(mod, filename) {
13491348
let source = getMaybeCachedSource(mod, filename);
13501349
if (getOptionValue('--experimental-strip-types') && path.extname(filename) === '.mts') {
1351-
if (isUnderNodeModules(filename)) {
1352-
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
1353-
}
13541350
source = stripTypeScriptTypes(source, filename);
13551351
}
13561352
const cascadedLoader = require('internal/modules/esm/loader').getOrInitializeCascadedLoader();
@@ -1587,9 +1583,6 @@ function getMaybeCachedSource(mod, filename) {
15871583
}
15881584

15891585
function loadCTS(module, filename) {
1590-
if (isUnderNodeModules(filename)) {
1591-
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
1592-
}
15931586
const source = getMaybeCachedSource(module, filename);
15941587
const code = stripTypeScriptTypes(source, filename);
15951588
module._compile(code, filename, 'commonjs');
@@ -1601,9 +1594,6 @@ function loadCTS(module, filename) {
16011594
* @param {string} filename The file path of the module
16021595
*/
16031596
function loadTS(module, filename) {
1604-
if (isUnderNodeModules(filename)) {
1605-
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
1606-
}
16071597
// If already analyzed the source, then it will be cached.
16081598
const source = getMaybeCachedSource(module, filename);
16091599
const content = stripTypeScriptTypes(source, filename);
Collapse file

‎lib/internal/modules/esm/load.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/load.js
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
RegExpPrototypeExec,
55
} = primordials;
66
const {
7-
isUnderNodeModules,
87
kEmptyObject,
98
} = require('internal/util');
109

@@ -23,7 +22,6 @@ const {
2322
ERR_INVALID_URL,
2423
ERR_UNKNOWN_MODULE_FORMAT,
2524
ERR_UNSUPPORTED_ESM_URL_SCHEME,
26-
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING,
2725
} = require('internal/errors').codes;
2826

2927
const {
@@ -131,12 +129,6 @@ async function defaultLoad(url, context = kEmptyObject) {
131129

132130
validateAttributes(url, format, importAttributes);
133131

134-
if (getOptionValue('--experimental-strip-types') &&
135-
(format === 'module-typescript' || format === 'commonjs-typescript') &&
136-
isUnderNodeModules(url)) {
137-
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(url);
138-
}
139-
140132
return {
141133
__proto__: null,
142134
format,
Collapse file

‎lib/internal/modules/helpers.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
ERR_INVALID_ARG_TYPE,
1717
ERR_INVALID_RETURN_PROPERTY_VALUE,
1818
ERR_INVALID_TYPESCRIPT_SYNTAX,
19+
ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING,
1920
} = require('internal/errors').codes;
2021
const { BuiltinModule } = require('internal/bootstrap/realm');
2122

@@ -28,7 +29,7 @@ const assert = require('internal/assert');
2829

2930
const { Buffer } = require('buffer');
3031
const { getOptionValue } = require('internal/options');
31-
const { assertTypeScript, setOwnProperty, getLazy } = require('internal/util');
32+
const { assertTypeScript, setOwnProperty, getLazy, isUnderNodeModules } = require('internal/util');
3233
const { inspect } = require('internal/util/inspect');
3334

3435
const lazyTmpdir = getLazy(() => require('os').tmpdir());
@@ -358,6 +359,9 @@ function parseTypeScript(source, options) {
358359
* @returns {TransformOutput} The stripped TypeScript code.
359360
*/
360361
function stripTypeScriptTypes(source, filename) {
362+
if (isUnderNodeModules(filename)) {
363+
throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename);
364+
}
361365
assert(typeof source === 'string');
362366
const options = {
363367
__proto__: null,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.