Skip to content

Commit

Permalink
build: fix typescript 3.9 compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-agius4 authored and mgechev committed Apr 27, 2020
1 parent 1b2847e commit f1119ff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
37 changes: 23 additions & 14 deletions packages/angular_devkit/core/src/utils/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/

export function mapObject<T, V>(obj: {[k: string]: T},
mapper: (k: string, v: T) => V): {[k: string]: V} {
return Object.keys(obj).reduce((acc: {[k: string]: V}, k: string) => {
export function mapObject<T, V>(obj: { [k: string]: T },
mapper: (k: string, v: T) => V): { [k: string]: V } {
return Object.keys(obj).reduce((acc: { [k: string]: V }, k: string) => {
acc[k] = mapper(k, obj[k]);

return acc;
Expand All @@ -19,24 +19,33 @@ export function mapObject<T, V>(obj: {[k: string]: T},
const copySymbol = Symbol();

// tslint:disable-next-line:no-any
export function deepCopy<T extends any> (value: T): T {
export function deepCopy<T extends any>(value: T): T {
if (Array.isArray(value)) {
return value.map((o: T) => deepCopy(o));
// tslint:disable-next-line:no-any
return value.map((o: any) => deepCopy(o)) as unknown as T;
} else if (value && typeof value === 'object') {
if (value[copySymbol]) {
const valueCasted = value as {
[copySymbol]?: T,
toJSON?: () => string,
// tslint:disable-next-line:no-any
[key: string]: any,
};

if (valueCasted[copySymbol]) {
// This is a circular dependency. Just return the cloned value.
return value[copySymbol];
return valueCasted[copySymbol] as T;
}
if (value['toJSON']) {
return JSON.parse((value['toJSON'] as () => string)());

if (valueCasted['toJSON']) {
return JSON.parse(valueCasted['toJSON']());
}

const copy = new (Object.getPrototypeOf(value).constructor)();
value[copySymbol] = copy;
for (const key of Object.getOwnPropertyNames(value)) {
copy[key] = deepCopy(value[key]);
const copy = new (Object.getPrototypeOf(valueCasted).constructor)();
valueCasted[copySymbol] = copy;
for (const key of Object.getOwnPropertyNames(valueCasted)) {
copy[key] = deepCopy(valueCasted[key]);
}
value[copySymbol] = undefined;
valueCasted[copySymbol] = undefined;

return copy;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/ngtools/webpack/src/compiler_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class WebpackCompilerHost implements ts.CompilerHost {
getCanonicalFileName(fileName: string): string {
const path = this.resolve(fileName);

return this.useCaseSensitiveFileNames ? path : path.toLowerCase();
return this.useCaseSensitiveFileNames() ? path : path.toLowerCase();
}

useCaseSensitiveFileNames(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function replaceResources(
return (context: ts.TransformationContext) => {
const typeChecker = getTypeChecker();

const visitNode: ts.Visitor = (node: ts.Decorator) => {
const visitNode: ts.Visitor = (node: ts.Node) => {
if (ts.isClassDeclaration(node)) {
const decorators = ts.visitNodes(
node.decorators,
Expand Down

0 comments on commit f1119ff

Please sign in to comment.