Skip to content

Library modularization #6990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8e5606e
Separate ES6 library feature-by-feature into smaller files
Feb 6, 2016
44aed7b
Feature-by-feature separate es7 library into smaller files
Feb 6, 2016
cbec78e
Rename core to es5
Feb 6, 2016
73534a4
Update building library files in JakeFile
Feb 9, 2016
00d619d
Separate iterable into its own file
Feb 11, 2016
1609c31
separate symbol into its own file
Feb 11, 2016
eb30193
separate well-known symbol into its own file
Feb 11, 2016
3b15eb0
remove iterable and symbol component from es6.string.d.ts
Feb 11, 2016
2f43778
remove iterable and symbol components from es6.array.d.ts
Feb 11, 2016
41e5b24
remove iterable and symbol components from es6.collection.d.ts
Feb 11, 2016
067fa12
remove symbol components from es6.math.d.ts
Feb 11, 2016
9fa06fd
remove iterable and symbol components from es6.object.d.ts
Feb 11, 2016
5200bf1
remove iterable and symbol components from es6.promise.d.ts
Feb 11, 2016
8616370
remove iterable and symbol component from es6.reflect.d.ts
Feb 11, 2016
16104a2
remove iterable and symbol components from es6.proxy.d.ts
Feb 11, 2016
f19bd4c
split function into its own file
Feb 11, 2016
005271e
split regexp into its own file
Feb 11, 2016
80f6920
remove unused file
Feb 11, 2016
37a7998
rename es7 array-include d.ts file
Feb 11, 2016
69e5045
Include new lib files into compilation
Feb 12, 2016
b461ab8
Move symbol.iterable to symbol.wellknown
Feb 19, 2016
08f1a77
Make iterable depends on symbol
Feb 19, 2016
4684313
Move functions/methods that use propertyKey back to its original inte…
Feb 19, 2016
6043a97
Rename dome.es6 to dom.iterable
Feb 20, 2016
1704059
Rename importcore.d.ts to importes5.d.ts
Feb 20, 2016
779ffe8
Add es6.d.ts and es7.d.ts that contain /// references to their associ…
Feb 20, 2016
8e902c2
Update library compilation
Feb 20, 2016
c33a7ac
Fix harness broken from renaming generated library files
Feb 23, 2016
fc42621
Update baselines
Feb 23, 2016
70f6969
Merge branch 'master' into breakinglibrary
Feb 23, 2016
8e20680
Remove intl.d.ts
Feb 26, 2016
3839898
Use lib.full.es6.d.ts instead of lib.es6.d.ts
Feb 26, 2016
c1290c1
Add intl.d.ts to es5.d.ts
Feb 26, 2016
77639de
Add missing WeakSet and Set to collection
Feb 26, 2016
b41009a
Remove unused RegexpConstructor interface
Feb 26, 2016
23cb32e
Separate generator into its own file
Feb 26, 2016
499b338
Update baselines
Feb 26, 2016
2d2bf11
Merge branch 'master' into breakinglibrary
Feb 26, 2016
4c89068
Update baseline from merging intl.d.ts into es5.d.ts
Feb 27, 2016
5509b48
Update Jakefile
Feb 29, 2016
3f5d374
Remove iterable-iterator dependence
Mar 2, 2016
f052835
Use lower case for lib filename
Mar 2, 2016
05fe71c
Merge branch 'master' into breakinglibrary
Mar 8, 2016
e5bbdec
Renaming scripthost file
Mar 9, 2016
8167317
Renaming scripthost file
Mar 9, 2016
fbb80ee
Merge branch 'breakinglibrary' of https://github.com/Microsoft/TypeSc…
Mar 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 45 additions & 10 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,53 @@ var harnessSources = harnessCoreSources.concat([
return path.join(serverDirectory, f);
}));

var librarySourceMap = [
{ target: "lib.core.d.ts", sources: ["header.d.ts", "core.d.ts"] },
{ target: "lib.dom.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "dom.generated.d.ts"], },
{ target: "lib.webworker.d.ts", sources: ["importcore.d.ts", "intl.d.ts", "webworker.generated.d.ts"], },
{ target: "lib.scriptHost.d.ts", sources: ["importcore.d.ts", "scriptHost.d.ts"], },
{ 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"], },
{ target: "lib.core.es6.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts"]},
{ 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"] },
{ target: "lib.core.es7.d.ts", sources: ["header.d.ts", "core.d.ts", "es6.d.ts", "es7.d.ts"]},
{ 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"] }
var es6LibrarySources = [
"es6.array.d.ts",
"es6.collection.d.ts",
"es6.function.d.ts",
"es6.generator.d.ts",
"es6.iterable.d.ts",
"es6.math.d.ts",
"es6.number.d.ts",
"es6.object.d.ts",
"es6.promise.d.ts",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about "dom.es6.d.ts"? i do not see this anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I am planning to do that in later pass with lib.node.d.ts and lib.browser.d.ts

"es6.proxy.d.ts",
"es6.reflect.d.ts",
"es6.regexp.d.ts",
"es6.string.d.ts",
"es6.symbol.d.ts",
"es6.symbol.wellknown.d.ts",
];

var es6LibrarySourceMap = es6LibrarySources.map(function(source) {
return { target: "lib." + source, sources: [source ] };
});

var es7LibrarySource = [ "es7.array.include.d.ts" ];

var es7LibrarySourceMap = es7LibrarySource.map(function(source) {
return { target: "lib." + source, sources: [source] };
})

var hostsLibrarySources = ["dom.generated.d.ts", "webworker.importscripts.d.ts", "scripthost.d.ts"]

var librarySourceMap = [
// Host library
{ target: "lib.dom.d.ts", sources: ["dom.generated.d.ts"], },
{ target: "lib.dom.iterable.d.ts", sources: ["dom.iterable.d.ts"], },
{ target: "lib.webworker.d.ts", sources: ["webworker.generated.d.ts"], },
{ target: "lib.scripthost.d.ts", sources: ["scripthost.d.ts"], },

// JavaScript library
{ target: "lib.es5.d.ts", sources: ["header.d.ts", "es5.d.ts"] },
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es6.d.ts"] },
{ target: "lib.es7.d.ts", sources: ["header.d.ts", "es7.d.ts"] },

// JavaScript + all host library
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources), },
{ target: "lib.full.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es6LibrarySources, hostsLibrarySources), },
].concat(es6LibrarySourceMap, es7LibrarySourceMap);

var libraryTargets = librarySourceMap.map(function (f) {
return path.join(builtLocalDirectory, f.target);
});
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ namespace ts {

namespace ts {
export function getDefaultLibFileName(options: CompilerOptions): string {
return options.target === ScriptTarget.ES6 ? "lib.es6.d.ts" : "lib.d.ts";
return options.target === ScriptTarget.ES6 ? "lib.full.es6.d.ts" : "lib.d.ts";
}

export function textSpanEnd(span: TextSpan) {
Expand Down
7 changes: 4 additions & 3 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,9 @@ namespace Harness {
const lineFeed = "\n";

export const defaultLibFileName = "lib.d.ts";
export const defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.core.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);
export const defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.core.es6.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);
export const defaultLibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i woudl use the es6.full instead

// 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
export const defaultES6LibSourceFile = createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.full.es6.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest);

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

export function isLibraryFile(filePath: string): boolean {
return (Path.getFileName(filePath) === "lib.d.ts") || (Path.getFileName(filePath) === "lib.core.d.ts");
return (Path.getFileName(filePath) === "lib.d.ts") || (Path.getFileName(filePath) === "lib.es5.d.ts");
}

export function isBuiltFile(filePath: string): boolean {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/dom.es6.d.ts → src/lib/dom.iterable.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference path="lib.dom.generated.d.ts" />

interface DOMTokenList {
[Symbol.iterator](): IterableIterator<string>;
}
Expand Down
203 changes: 203 additions & 0 deletions src/lib/core.d.ts → src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,8 @@ interface TypedPropertyDescriptor<T> {
set?: (value: T) => void;
}

declare type PropertyKey = string | number | symbol;

declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
Expand Down Expand Up @@ -3904,3 +3906,204 @@ interface Float64ArrayConstructor {
from(arrayLike: ArrayLike<number>, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
}
declare const Float64Array: Float64ArrayConstructor;

/////////////////////////////
/// ECMAScript Internationalization API
/////////////////////////////

declare module Intl {
interface CollatorOptions {
usage?: string;
localeMatcher?: string;
numeric?: boolean;
caseFirst?: string;
sensitivity?: string;
ignorePunctuation?: boolean;
}

interface ResolvedCollatorOptions {
locale: string;
usage: string;
sensitivity: string;
ignorePunctuation: boolean;
collation: string;
caseFirst: string;
numeric: boolean;
}

interface Collator {
compare(x: string, y: string): number;
resolvedOptions(): ResolvedCollatorOptions;
}
var Collator: {
new (locales?: string[], options?: CollatorOptions): Collator;
new (locale?: string, options?: CollatorOptions): Collator;
(locales?: string[], options?: CollatorOptions): Collator;
(locale?: string, options?: CollatorOptions): Collator;
supportedLocalesOf(locales: string[], options?: CollatorOptions): string[];
supportedLocalesOf(locale: string, options?: CollatorOptions): string[];
}

interface NumberFormatOptions {
localeMatcher?: string;
style?: string;
currency?: string;
currencyDisplay?: string;
useGrouping?: boolean;
minimumIntegerDigits?: number;
minimumFractionDigits?: number;
maximumFractionDigits?: number;
minimumSignificantDigits?: number;
maximumSignificantDigits?: number;
}

interface ResolvedNumberFormatOptions {
locale: string;
numberingSystem: string;
style: string;
currency?: string;
currencyDisplay?: string;
minimumIntegerDigits: number;
minimumFractionDigits: number;
maximumFractionDigits: number;
minimumSignificantDigits?: number;
maximumSignificantDigits?: number;
useGrouping: boolean;
}

interface NumberFormat {
format(value: number): string;
resolvedOptions(): ResolvedNumberFormatOptions;
}
var NumberFormat: {
new (locales?: string[], options?: NumberFormatOptions): NumberFormat;
new (locale?: string, options?: NumberFormatOptions): NumberFormat;
(locales?: string[], options?: NumberFormatOptions): NumberFormat;
(locale?: string, options?: NumberFormatOptions): NumberFormat;
supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[];
supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[];
}

interface DateTimeFormatOptions {
localeMatcher?: string;
weekday?: string;
era?: string;
year?: string;
month?: string;
day?: string;
hour?: string;
minute?: string;
second?: string;
timeZoneName?: string;
formatMatcher?: string;
hour12?: boolean;
timeZone?: string;
}

interface ResolvedDateTimeFormatOptions {
locale: string;
calendar: string;
numberingSystem: string;
timeZone: string;
hour12?: boolean;
weekday?: string;
era?: string;
year?: string;
month?: string;
day?: string;
hour?: string;
minute?: string;
second?: string;
timeZoneName?: string;
}

interface DateTimeFormat {
format(date?: Date | number): string;
resolvedOptions(): ResolvedDateTimeFormatOptions;
}
var DateTimeFormat: {
new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat;
new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat;
(locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat;
(locale?: string, options?: DateTimeFormatOptions): DateTimeFormat;
supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[];
supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[];
}
}

interface String {
/**
* Determines whether two strings are equivalent in the current locale.
* @param that String to compare to target string
* @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.
* @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details.
*/
localeCompare(that: string, locales: string[], options?: Intl.CollatorOptions): number;

/**
* Determines whether two strings are equivalent in the current locale.
* @param that String to compare to target string
* @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.
* @param options An object that contains one or more properties that specify comparison options. see the Intl.Collator object for details.
*/
localeCompare(that: string, locale: string, options?: Intl.CollatorOptions): number;
}

interface Number {
/**
* Converts a number to a string by using the current or specified locale.
* @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.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleString(locales?: string[], options?: Intl.NumberFormatOptions): string;

/**
* Converts a number to a string by using the current or specified locale.
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleString(locale?: string, options?: Intl.NumberFormatOptions): string;
}

interface Date {
/**
* Converts a date and time to a string by using the current or specified locale.
* @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.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleString(locales?: string[], options?: Intl.DateTimeFormatOptions): string;
/**
* Converts a date to a string by using the current or specified locale.
* @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.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleDateString(locales?: string[], options?: Intl.DateTimeFormatOptions): string;

/**
* Converts a time to a string by using the current or specified locale.
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleTimeString(locale?: string[], options?: Intl.DateTimeFormatOptions): string;

/**
* Converts a date and time to a string by using the current or specified locale.
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string;

/**
* Converts a date to a string by using the current or specified locale.
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleDateString(locale?: string, options?: Intl.DateTimeFormatOptions): string;

/**
* Converts a time to a string by using the current or specified locale.
* @param locale Locale tag. If you omit this parameter, the default locale of the JavaScript runtime is used.
* @param options An object that contains one or more properties that specify comparison options.
*/
toLocaleTimeString(locale?: string, options?: Intl.DateTimeFormatOptions): string;
}
67 changes: 67 additions & 0 deletions src/lib/es6.array.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
interface Array<T> {
/**
* Returns the value of the first element in the array where predicate is true, and undefined
* otherwise.
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found, find
* immediately returns that element value. Otherwise, find returns undefined.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
find(predicate: (value: T, index: number, obj: Array<T>) => boolean, thisArg?: any): T;

/**
* Returns the index of the first element in the array where predicate is true, and undefined
* otherwise.
* @param predicate find calls predicate once for each element of the array, in ascending
* order, until it finds one where predicate returns true. If such an element is found, find
* immediately returns that element value. Otherwise, find returns undefined.
* @param thisArg If provided, it will be used as the this value for each invocation of
* predicate. If it is not provided, undefined is used instead.
*/
findIndex(predicate: (value: T) => boolean, thisArg?: any): number;

/**
* Returns the this object after filling the section identified by start and end with value
* @param value value to fill array section with
* @param start index to start filling the array at. If start is negative, it is treated as
* length+start where length is the length of the array.
* @param end index to stop filling the array at. If end is negative, it is treated as
* length+end.
*/
fill(value: T, start?: number, end?: number): T[];

/**
* Returns the this object after copying a section of the array identified by start and end
* to the same array starting at position target
* @param target If target is negative, it is treated as length+target where length is the
* length of the array.
* @param start If start is negative, it is treated as length+start. If end is negative, it
* is treated as length+end.
* @param end If not specified, length of the this object is used as its default value.
*/
copyWithin(target: number, start: number, end?: number): T[];
}

interface ArrayConstructor {
/**
* Creates an array from an array-like object.
* @param arrayLike An array-like object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
from<T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): Array<U>;


/**
* Creates an array from an array-like object.
* @param arrayLike An array-like object to convert to an array.
*/
from<T>(arrayLike: ArrayLike<T>): Array<T>;

/**
* Returns a new array from a set of elements.
* @param items A set of elements to include in the new array object.
*/
of<T>(...items: T[]): Array<T>;
}
Loading