Skip to content

Commit 90edb23

Browse files
committed
Exclude type's export ability
1 parent 53b61d8 commit 90edb23

File tree

9 files changed

+88
-71
lines changed

9 files changed

+88
-71
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
declare global {
2-
var self: typeof globalThis extends { onmessage: any; self: infer T } ? T : {
3-
URL?: typeof URL;
4-
};
2+
var self: typeof globalThis extends { onmessage: any; self: infer T } ? T : {};
53
}
64

75
export {};
Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
/// <reference types="../core-js-modules/url" />
2-
3-
import * as url from 'core-js/internals/web/url';
4-
5-
declare global {
6-
interface URL extends url.URL {}
7-
var URL: typeof globalThis extends { onmessage: any; URL: infer T } ? T : typeof url.URL;
8-
9-
interface URLSearchParams extends url.URLSearchParams {}
10-
var URLSearchParams: typeof globalThis extends { onmessage: any; URLSearchParams: infer T } ? T
11-
: typeof url.URLSearchParams;
12-
}
13-
14-
export {};
1+
// URL has conflicts with @types/node
2+
// /// <reference types="../core-js-modules/url" />
3+
4+
// import * as url from 'core-js/internals/web/url';
5+
//
6+
// declare global {
7+
// interface URL extends url.URL {}
8+
// var URL: typeof globalThis extends { onmessage: any; URL: infer T } ? T : typeof url.URL;
9+
//
10+
// interface URLSearchParams extends url.URLSearchParams {}
11+
// var URLSearchParams: typeof globalThis extends { onmessage: any; URLSearchParams: infer T } ? T
12+
// : typeof url.URLSearchParams;
13+
// }
14+
//
15+
// export {};

packages/core-js/modules/web.url.constructor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// types: web/url
1+
// no types: because of a conflict with @types/node
22
'use strict';
33
var $ = require('../internals/export');
44
var USE_NATIVE_URL = require('../internals/url-constructor-detection');

scripts/build-entries/entries-definitions.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,37 +3073,44 @@ export const features = {
30733073
modules: [/^web\.url(?:-search-params)?\./],
30743074
template: $namespace,
30753075
name: 'URL',
3076+
globalType: false,
30763077
},
30773078
'url/constructor': {
30783079
modules: ['web.url.constructor', 'web.url.to-json', /^web\.url-search-params?\./],
30793080
template: $namespace,
30803081
name: 'URL',
3082+
globalType: false,
30813083
},
30823084
'url/can-parse': {
30833085
modules: ['web.url.can-parse'],
30843086
template: $static,
30853087
namespace: 'URL',
30863088
name: 'canParse',
3089+
globalType: false,
30873090
},
30883091
'url/parse': {
30893092
modules: ['web.url.parse'],
30903093
template: $static,
30913094
namespace: 'URL',
30923095
name: 'parse',
3096+
globalType: false,
30933097
},
30943098
'url/to-json': {
30953099
modules: ['web.url.to-json'],
30963100
template: $justImport,
3101+
globalType: false,
30973102
},
30983103
'url-search-params/index': {
30993104
modules: [/^web\.url-search-params\./],
31003105
template: $namespace,
31013106
name: 'URLSearchParams',
3107+
globalType: false,
31023108
},
31033109
'url-search-params/constructor': {
31043110
modules: [/^web\.url-search-params\./],
31053111
template: $namespace,
31063112
name: 'URLSearchParams',
3113+
globalType: false,
31073114
},
31083115
'weak-map/index': {
31093116
modules: [/^(?:es|esnext)\.weak-map\./],

scripts/build-types/index.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ const imports = {
2929
let outputFiles = {};
3030

3131
function addType(tsVersion, subset, template, options) {
32+
const exportGlobalType = options.globalType ?? true;
33+
if (!exportGlobalType && subset !== 'pure') {
34+
return;
35+
}
3236
const filePath = buildFilePath(tsVersion, subset);
3337
if (!outputFiles[filePath]) outputFiles[filePath] = '';
3438
const entryWithTypes = template(options);
@@ -44,6 +48,8 @@ async function buildType(entry, options) {
4448
let {
4549
entryFromNamespace,
4650
subset = entryFromNamespace ?? 'full',
51+
globalType,
52+
exportGlobalType = globalType ?? true,
4753
template, templateStable, templateActual, templateFull, filter, modules, enforceEntryCreation,
4854
customType, tsVersion, proposal, types, ownEntryPoint,
4955
} = options;
@@ -77,14 +83,18 @@ async function buildType(entry, options) {
7783
}
7884

7985
types.forEach(type => {
80-
imports.index.add(type);
81-
imports[subset].add(type);
86+
if (exportGlobalType) {
87+
imports.index.add(type);
88+
imports[subset].add(type);
89+
}
8290
imports.pure.add(path.join('pure', type));
8391
});
8492

8593
if (customType) {
86-
imports.index.add(customType);
87-
imports[subset].add(customType);
94+
if (exportGlobalType) {
95+
imports.index.add(customType);
96+
imports[subset].add(customType);
97+
}
8898
imports.pure.add(path.join('pure', customType));
8999
}
90100
options = { ...options, modules, level, entry, types };
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
// todo add after it becomes possible to create a type
2-
// import 'core-js/full';
3-
//
4-
// const ex1 = new DOMException();
5-
// const ex2 = new DOMException('Some message');
6-
// const ex3 = new DOMException('Some message', 'SyntaxError');
7-
//
8-
// // @ts-expect-error
9-
// // DOMException();
10-
// // @ts-expect-error
11-
// DOMException(123);
1+
import 'core-js/full';
2+
3+
const ex1 = new DOMException();
4+
const ex2 = new DOMException('Some message');
5+
const ex3 = new DOMException('Some message', 'SyntaxError');
6+
7+
// @ts-expect-error
8+
DOMException();
9+
// @ts-expect-error
10+
DOMException(123);
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import 'core-js/full';
2-
3-
const u1: URL | null = URL.parse('https://example.com/path?name=value#hash');
4-
URL.parse('/path', 'https://example.com');
5-
6-
if (u1) {
7-
let str: string;
8-
str = u1.pathname;
9-
str = u1.hostname;
10-
str = u1.pathname;
11-
12-
str = u1.toJSON();
13-
str = u1.toString();
14-
}
15-
16-
// @ts-expect-error
17-
URL.parse(null);
1+
// URL has conflicts with @types/node
2+
// import 'core-js/full';
3+
//
4+
// const u1: URL | null = URL.parse('https://example.com/path?name=value#hash');
5+
// URL.parse('/path', 'https://example.com');
6+
//
7+
// if (u1) {
8+
// let str: string;
9+
// str = u1.pathname;
10+
// str = u1.hostname;
11+
// str = u1.pathname;
12+
//
13+
// str = u1.toJSON();
14+
// str = u1.toString();
15+
// }
16+
//
17+
// // @ts-expect-error
18+
// URL.parse(null);
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import 'core-js/full';
2-
3-
const u0 = new URLSearchParams();
4-
const u1 = new URLSearchParams('a=1&b=2');
5-
const u2 = new URLSearchParams([['a', '1'], ['b', '2']]);
6-
const u3 = new URLSearchParams({ a: '1', b: '2' });
7-
8-
// @ts-expect-error
9-
new URLSearchParams(123);
10-
// @ts-expect-error
11-
new URLSearchParams([1, 2, 3]);
1+
// URL has conflicts with @types/node
2+
// import 'core-js/full';
3+
//
4+
// const u0 = new URLSearchParams();
5+
// const u1 = new URLSearchParams('a=1&b=2');
6+
// const u2 = new URLSearchParams([['a', '1'], ['b', '2']]);
7+
// const u3 = new URLSearchParams({ a: '1', b: '2' });
8+
//
9+
// // @ts-expect-error
10+
// new URLSearchParams(123);
11+
// // @ts-expect-error
12+
// new URLSearchParams([1, 2, 3]);

tests/type-definitions/global/web/url-to-json.dom.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import 'core-js/full';
2-
3-
declare const urlLike: URL;
4-
const str: string = urlLike.toJSON();
5-
6-
// @ts-expect-error
7-
const num: number = urlLike.toJSON();
8-
// @ts-expect-error
9-
urlLike.toJSON('param');
1+
// URL has conflicts with @types/node
2+
// import 'core-js/full';
3+
//
4+
// declare const urlLike: URL;
5+
// const str: string = urlLike.toJSON();
6+
//
7+
// // @ts-expect-error
8+
// const num: number = urlLike.toJSON();
9+
// // @ts-expect-error
10+
// urlLike.toJSON('param');
1011

11-
// todo add after URL becomes constructable in types
1212
// const url1 = new URL('https://example.com');
1313
// new URL('page', 'https://example.com');
1414
// new URL('/path', url1);

0 commit comments

Comments
 (0)