1 | /// <amd-module name="@angular/compiler-cli/ngcc/src/packages/patch_ts_expando_initializer" />
|
---|
2 | /**
|
---|
3 | * Consider the following ES5 code that may have been generated for a class:
|
---|
4 | *
|
---|
5 | * ```
|
---|
6 | * var A = (function(){
|
---|
7 | * function A() {}
|
---|
8 | * return A;
|
---|
9 | * }());
|
---|
10 | * A.staticProp = true;
|
---|
11 | * ```
|
---|
12 | *
|
---|
13 | * Here, TypeScript marks the symbol for "A" as a so-called "expando symbol", which causes
|
---|
14 | * "staticProp" to be added as an export of the "A" symbol.
|
---|
15 | *
|
---|
16 | * In the example above, symbol "A" has been assigned some flags to indicate that it represents a
|
---|
17 | * class. Due to this flag, the symbol is considered an expando symbol and as such, "staticProp" is
|
---|
18 | * stored in `ts.Symbol.exports`.
|
---|
19 | *
|
---|
20 | * A problem arises when "A" is not at the top-level, i.e. in UMD bundles. In that case, the symbol
|
---|
21 | * does not have the flag that marks the symbol as a class. Therefore, TypeScript inspects "A"'s
|
---|
22 | * initializer expression, which is an IIFE in the above example. Unfortunately however, only IIFEs
|
---|
23 | * of the form `(function(){})()` qualify as initializer for an "expando symbol"; the slightly
|
---|
24 | * different form seen in the example above, `(function(){}())`, does not. This prevents the "A"
|
---|
25 | * symbol from being considered an expando symbol, in turn preventing "staticProp" from being stored
|
---|
26 | * in `ts.Symbol.exports`.
|
---|
27 | *
|
---|
28 | * The logic for identifying symbols as "expando symbols" can be found here:
|
---|
29 | * https://github.com/microsoft/TypeScript/blob/v3.4.5/src/compiler/binder.ts#L2656-L2685
|
---|
30 | *
|
---|
31 | * Notice how the `getExpandoInitializer` function is available on the "ts" namespace in the
|
---|
32 | * compiled bundle, so we are able to override this function to accommodate for the alternative
|
---|
33 | * IIFE notation. The original implementation can be found at:
|
---|
34 | * https://github.com/Microsoft/TypeScript/blob/v3.4.5/src/compiler/utilities.ts#L1864-L1887
|
---|
35 | *
|
---|
36 | * Issue tracked in https://github.com/microsoft/TypeScript/issues/31778
|
---|
37 | *
|
---|
38 | * @returns the function to pass to `restoreGetExpandoInitializer` to undo the patch, or null if
|
---|
39 | * the issue is known to have been fixed.
|
---|
40 | */
|
---|
41 | export declare function patchTsGetExpandoInitializer(): unknown;
|
---|
42 | export declare function restoreGetExpandoInitializer(originalGetExpandoInitializer: unknown): void;
|
---|