Skip to content

Commit 168118f

Browse files
author
Kanchalai Tanglertsampan
committed
Modularize ES6 and ES7 library files
Separate ES6 library feature-by-feature into smaller files Break ES6 library Remove unused ES6 Rename core to es5 Update building library files in JakeFile separate symbol into its own file separate well-known symbol into its own file remove iterable and symbol component from es6.string.d.ts remove iterable and symbol components from es6.collection.d.ts remove symbol components from es6.math.d.ts remove iterable and symbol components from es6.object.d.ts remove iterable and symbol components from es6.promise.d.ts remove iterable and symbol component from es6.reflect.d.ts remove iterable and symbol components from es6.proxy.d.ts split regexp into its own file remove unused file rename es7 array-include d.ts file Include new lib files into compilation Move symbol.iterable to symbol.wellknown Move functions/methods that use propertyKey back to its original interface Rename dome.es6 to dom.iterable Take dependency on dom.generated.d.ts Rename importcore.d.ts to importes5.d.ts Add es6.d.ts and es7.d.ts that contain /// references to their associated sub-features files Update library compilation Fix harness broken from renaming generated library files Remove intl.d.ts Remove preset lib files Use lib.full.es6.d.ts instead of lib.es6.d.ts Add intl.d.ts to es5.d.ts Remove unused RegexpConstructor interface Separate generator into its own file Update Jakefile Remove iterable-iterator dependence Use lower case for lib filename Include no-default comment Remove newline on top of the file
1 parent 89350b3 commit 168118f

26 files changed

+1439
-1639
lines changed

Jakefile.js

+45-10
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,53 @@ var harnessSources = harnessCoreSources.concat([
165165
return path.join(serverDirectory, f);
166166
}));
167167

168-
var librarySourceMap = [
169-
{ target: "lib.core.d.ts", sources: ["header.d.ts", "core.d.ts"] },
170-
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "dom.generated.d.ts"], },
171-
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "webworker.generated.d.ts"], },
172-
{ target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"], },
173-
{ target: "lib.d.ts", sources: ["header.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"], },
174-
{ target: "lib.core.es6.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts"]},
175-
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es6.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "dom.es6.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] },
176-
{ target: "lib.core.es7.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts", "es7.d.ts"]},
177-
{ target: "lib.es7.d.ts", sources: ["header.d.ts", "es6.d.ts", "es7.d.ts", "core.d.ts", "intl.d.ts", "dom.generated.d.ts", "dom.es6.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"] }
168+
var es6LibrarySources = [
169+
"es6.array.d.ts",
170+
"es6.collection.d.ts",
171+
"es6.function.d.ts",
172+
"es6.generator.d.ts",
173+
"es6.iterable.d.ts",
174+
"es6.math.d.ts",
175+
"es6.number.d.ts",
176+
"es6.object.d.ts",
177+
"es6.promise.d.ts",
178+
"es6.proxy.d.ts",
179+
"es6.reflect.d.ts",
180+
"es6.regexp.d.ts",
181+
"es6.string.d.ts",
182+
"es6.symbol.d.ts",
183+
"es6.symbol.wellknown.d.ts",
178184
];
179185

186+
var es6LibrarySourceMap = es6LibrarySources.map(function(source) {
187+
return { target: "lib." + source, sources: ["header.d.ts", source] };
188+
});
189+
190+
var es7LibrarySource = [ "es7.array.include.d.ts" ];
191+
192+
var es7LibrarySourceMap = es7LibrarySource.map(function(source) {
193+
return { target: "lib." + source, sources: ["header.d.ts", source] };
194+
})
195+
196+
var hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scriptHost.d.ts"]
197+
198+
var librarySourceMap = [
199+
// Host library
200+
{ target: "lib.dom.d.ts", sources: ["header.d.ts", "dom.generated.d.ts"], },
201+
{ target: "lib.dom.iterable.d.ts", sources: ["header.d.ts", "dom.iterable.d.ts"], },
202+
{ target: "lib.webworker.d.ts", sources: ["header.d.ts", "webworker.generated.d.ts"], },
203+
{ target: "lib.scripthost.d.ts", sources: ["header.d.ts", "scripthost.d.ts"], },
204+
205+
// JavaScript library
206+
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
207+
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es6.d.ts"] },
208+
{ target: "lib.es7.d.ts", sources: ["header.d.ts", "es7.d.ts"] },
209+
210+
// JavaScript + all host library
211+
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources), },
212+
{ target: "lib.full.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es6LibrarySources, hostsLibrarySources), },
213+
].concat(es6LibrarySourceMap, es7LibrarySourceMap);
214+
180215
var libraryTargets = librarySourceMap.map(function (f) {
181216
return path.join(builtLocalDirectory, f.target);
182217
});

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,7 @@ namespace ts {
26462646

26472647
namespace ts {
26482648
export function getDefaultLibFileName(options: CompilerOptions): string {
2649-
return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts";
2649+
return options.target === ScriptTarget.ES6 ? "lib.full.es6.d.ts" : "lib.d.ts";
26502650
}
26512651

26522652
export function textSpanEnd(span: TextSpan) {

src/harness/harness.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,9 @@ namespace Harness {
809809
const lineFeed = "\n";
810810

811811
export const defaultLibFileName = "lib.d.ts";
812-
export const defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.core.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);
813-
export const defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.core.es6.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);
812+
export const defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);
813+
// TODO (yuisu): we should not use the lib.full.es6.d.ts. We will fix this when all the work for library modularization is in
814+
export const defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.full.es6.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);
814815

815816
// Cache these between executions so we don't have to re-parse them for every test
816817
export const fourslashFileName = "fourslash.ts";
@@ -1606,7 +1607,7 @@ namespace Harness {
16061607
}
16071608

16081609
export function isLibraryFile(filePath: string): boolean {
1609-
return (Path.getFileName(filePath) === "lib.d.ts") || (Path.getFileName(filePath) === "lib.core.d.ts");
1610+
return (Path.getFileName(filePath) === "lib.d.ts") || (Path.getFileName(filePath) === "lib.es5.d.ts");
16101611
}
16111612

16121613
export function isBuiltFile(filePath: string): boolean {

src/lib/dom.generated.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/////////////////////////////
32
/// IE DOM APIs
43
/////////////////////////////

src/lib/dom.es6.d.ts renamed to src/lib/dom.iterable.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/// <reference path="lib.dom.generated.d.ts" />
2+
13
interface DOMTokenList {
24
[Symbol.iterator](): IterableIterator<string>;
35
}

src/lib/core.d.ts renamed to src/lib/es5.d.ts

+203
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,8 @@ interface TypedPropertyDescriptor<T> {
12471247
set?: (value: T) => void;
12481248
}
12491249

1250+
declare type PropertyKey = string | number | symbol;
1251+
12501252
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
12511253
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
12521254
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
@@ -3904,3 +3906,204 @@ interface Float64ArrayConstructor {
39043906
from(arrayLike: ArrayLike<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
39053907
}
39063908
declare const Float64Array: Float64ArrayConstructor;
3909+
3910+
/////////////////////////////
3911+
/// ECMAScript Internationalization API
3912+
/////////////////////////////
3913+
3914+
declare module Intl {
3915+
interface CollatorOptions {
3916+
usage?: string;
3917+
localeMatcher?: string;
3918+
numeric?: boolean;
3919+
caseFirst?: string;
3920+
sensitivity?: string;
3921+
ignorePunctuation?: boolean;
3922+
}
3923+
3924+
interface ResolvedCollatorOptions {
3925+
locale: string;
3926+
usage: string;
3927+
sensitivity: string;
3928+
ignorePunctuation: boolean;
3929+
collation: string;
3930+
caseFirst: string;
3931+
numeric: boolean;
3932+
}
3933+
3934+
interface Collator {
3935+
compare(x: string, y: string): number;
3936+
resolvedOptions(): ResolvedCollatorOptions;
3937+
}
3938+
var Collator: {
3939+
new (locales?: string[], options?: CollatorOptions): Collator;
3940+
new (locale?: string, options?: CollatorOptions): Collator;
3941+
(locales?: string[], options?: CollatorOptions): Collator;
3942+
(locale?: string, options?: CollatorOptions): Collator;
3943+
supportedLocalesOf(locales: string[], options?: CollatorOptions): string[];
3944+
supportedLocalesOf(locale: string, options?: CollatorOptions): string[];
3945+
}
3946+
3947+
interface NumberFormatOptions {
3948+
localeMatcher?: string;
3949+
style?: string;
3950+
currency?: string;
3951+
currencyDisplay?: string;
3952+
useGrouping?: boolean;
3953+
minimumIntegerDigits?: number;
3954+
minimumFractionDigits?: number;
3955+
maximumFractionDigits?: number;
3956+
minimumSignificantDigits?: number;
3957+
maximumSignificantDigits?: number;
3958+
}
3959+
3960+
interface ResolvedNumberFormatOptions {
3961+
locale: string;
3962+
numberingSystem: string;
3963+
style: string;
3964+
currency?: string;
3965+
currencyDisplay?: string;
3966+
minimumIntegerDigits: number;
3967+
minimumFractionDigits: number;
3968+
maximumFractionDigits: number;
3969+
minimumSignificantDigits?: number;
3970+
maximumSignificantDigits?: number;
3971+
useGrouping: boolean;
3972+
}
3973+
3974+
interface NumberFormat {
3975+
format(value: number): string;
3976+
resolvedOptions(): ResolvedNumberFormatOptions;
3977+
}
3978+
var NumberFormat: {
3979+
new (locales?: string[], options?: NumberFormatOptions): NumberFormat;
3980+
new (locale?: string, options?: NumberFormatOptions): NumberFormat;
3981+
(locales?: string[], options?: NumberFormatOptions): NumberFormat;
3982+
(locale?: string, options?: NumberFormatOptions): NumberFormat;
3983+
supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[];
3984+
supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[];
3985+
}
3986+
3987+
interface DateTimeFormatOptions {
3988+
localeMatcher?: string;
3989+
weekday?: string;
3990+
era?: string;
3991+
year?: string;
3992+
month?: string;
3993+
day?: string;
3994+
hour?: string;
3995+
minute?: string;
3996+
second?: string;
3997+
timeZoneName?: string;
3998+
formatMatcher?: string;
3999+
hour12?: boolean;
4000+
timeZone?: string;
4001+
}
4002+
4003+
interface ResolvedDateTimeFormatOptions {
4004+
locale: string;
4005+
calendar: string;
4006+
numberingSystem: string;
4007+
timeZone: string;
4008+
hour12?: boolean;
4009+
weekday?: string;
4010+
era?: string;
4011+
year?: string;
4012+
month?: string;
4013+
day?: string;
4014+
hour?: string;
4015+
minute?: string;
4016+
second?: string;
4017+
timeZoneName?: string;
4018+
}
4019+
4020+
interface DateTimeFormat {
4021+
format(date?: Date | number): string;
4022+
resolvedOptions(): ResolvedDateTimeFormatOptions;
4023+
}
4024+
var DateTimeFormat: {
4025+
new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat;
4026+
new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat;
4027+
(locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat;
4028+
(locale?: string, options?: DateTimeFormatOptions): DateTimeFormat;
4029+
supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[];
4030+
supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[];
4031+
}
4032+
}
4033+
4034+
interface String {
4035+
/**
4036+
* Determines whether two strings are equivalent in the current locale.
4037+
* @param that String to compare to target string
4038+
* @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details.
4039+
* @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details.
4040+
*/
4041+
localeCompare(that: string, locales: string[], options?: Intl.CollatorOptions): number;
4042+
4043+
/**
4044+
* Determines whether two strings are equivalent in the current locale.
4045+
* @param that String to compare to target string
4046+
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used. This parameter must conform to BCP 47 standards; see the Intl.Collator object for details.
4047+
* @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details.
4048+
*/
4049+
localeCompare(that: string, locale: string, options?: Intl.CollatorOptions): number;
4050+
}
4051+
4052+
interface Number {
4053+
/**
4054+
* Converts a number to a string by using the current or specified locale.
4055+
* @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
4056+
* @param options An object that contains one or more properties that specify comparison options.
4057+
*/
4058+
toLocaleString(locales?: string[], options?: Intl.NumberFormatOptions): string;
4059+
4060+
/**
4061+
* Converts a number to a string by using the current or specified locale.
4062+
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
4063+
* @param options An object that contains one or more properties that specify comparison options.
4064+
*/
4065+
toLocaleString(locale?: string, options?: Intl.NumberFormatOptions): string;
4066+
}
4067+
4068+
interface Date {
4069+
/**
4070+
* Converts a date and time to a string by using the current or specified locale.
4071+
* @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
4072+
* @param options An object that contains one or more properties that specify comparison options.
4073+
*/
4074+
toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string;
4075+
/**
4076+
* Converts a date to a string by using the current or specified locale.
4077+
* @param locales An array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
4078+
* @param options An object that contains one or more properties that specify comparison options.
4079+
*/
4080+
toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string;
4081+
4082+
/**
4083+
* Converts a time to a string by using the current or specified locale.
4084+
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
4085+
* @param options An object that contains one or more properties that specify comparison options.
4086+
*/
4087+
toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string;
4088+
4089+
/**
4090+
* Converts a date and time to a string by using the current or specified locale.
4091+
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
4092+
* @param options An object that contains one or more properties that specify comparison options.
4093+
*/
4094+
toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string;
4095+
4096+
/**
4097+
* Converts a date to a string by using the current or specified locale.
4098+
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
4099+
* @param options An object that contains one or more properties that specify comparison options.
4100+
*/
4101+
toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string;
4102+
4103+
/**
4104+
* Converts a time to a string by using the current or specified locale.
4105+
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
4106+
* @param options An object that contains one or more properties that specify comparison options.
4107+
*/
4108+
toLocaleTimeString(locale?: string, options?: Intl.DateTimeFormatOptions): string;
4109+
}

0 commit comments

Comments
 (0)