Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: angular/tsickle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.46.0
Choose a base ref
...
head repository: angular/tsickle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.46.3
Choose a head ref

Commits on Jan 25, 2022

  1. Merge pull request #1323 from angular:v0.46

    PiperOrigin-RevId: 424073414
    copybara-github committed Jan 25, 2022
    Copy the full SHA
    cf501a2 View commit details

Commits on Jan 27, 2022

  1. Improve tsickle release scripts.

    * make sure to build before npm publish and npm pack.
    * use $(yarn bin) in scripts to make them less dependent on directory
      layout.
    * submit yarn.lock files for reproducible dependencies.
    * add a .gitignore (which was lost in some internal/external sync).
    mprobst committed Jan 27, 2022
    Copy the full SHA
    29b045f View commit details
  2. Merge pull request #1324 from angular:fixup

    PiperOrigin-RevId: 424606234
    copybara-github committed Jan 27, 2022
    Copy the full SHA
    1802902 View commit details

Commits on Feb 1, 2022

  1. tsickle: emit tsmes.js file in ES5 and Closure modes.

    Previously, tsickle somewhat awkwardly emitted the tsmes shim only when running
    in "closure" mode, which it probed by inspecting whether type annotation was
    requested. In that mode, it'd emit `.tsmes.closure.js`, and also remove the
    tsmes calls from source.
    
    In ES5 mode, presumably to avoid emitting two files (?), it instead produced a
    `.d.ts` file, and instead of replacing the tsmes calls, it'd inline equivalent
    logic. This was presumably done so that in dev mode, things would still work at
    runtime by registering the shim module ID.
    
    This setup doesn't work though: various tools expect an actual goog.module()
    call to be found for the shim module ID, so these do not work with the ES5
    sources. In addition, emitting a different set of files depending on contextual
    information, is confusing and breaks other tools that expect the same set of
    files in either run mode.
    
    This change:
    * unconditionally always emits the .tsmes.js file, and leaves it to the
      compiler host to write to .closure.js or .js (same as we do for all other JS
      files).
    * produces a .d.ts when the `.declaration` TS compiler option is set,
      equivalent to how .d.ts are produced from regular sources.
    * remove Generator.run(), which previously performed very different operations
      depending on arguments. Instead, this inlines some of the logic into the
      transformer function and makes explicit calls into the generator's functions.
    * refrains from further refactoring, though I'm leaving a TODO with some ideas.
    
    PiperOrigin-RevId: 425621974
    mprobst authored and copybara-github committed Feb 1, 2022
    Copy the full SHA
    b38aefc View commit details

Commits on Feb 2, 2022

  1. Changes ReadonlyArray, ReadonlySet, ReadonlyMap to @typedefs

    PiperOrigin-RevId: 425865101
    tsjs-language-eng authored and copybara-github committed Feb 2, 2022
    Copy the full SHA
    888aba2 View commit details

Commits on Feb 9, 2022

  1. Prevent property renaming of internal TypeScript API usages

    PiperOrigin-RevId: 427466150
    frigus02 authored and copybara-github committed Feb 9, 2022
    Copy the full SHA
    e482bc9 View commit details

Commits on Feb 24, 2022

  1. Add repro for b/210038368

    The decls.d.ts file was generated via running Clutz over the three .js files.
    
    The bug is that the type declarations in import_from_goog.js refer to module$exports$... or module$contents$... not tsickle_reexport_from_goog_1
    
    PiperOrigin-RevId: 430768437
    lauraharker authored and copybara-github committed Feb 24, 2022
    Copy the full SHA
    f06e2e7 View commit details

Commits on Mar 3, 2022

  1. Translate {}/unknown in constructed types to ?

    PiperOrigin-RevId: 432208899
    frigus02 authored and copybara-github committed Mar 3, 2022
    Copy the full SHA
    d863eef View commit details

Commits on Mar 22, 2022

  1. Add support for tsMigrationExportsShimDeclareLegacyNamespace to tsick…

    …le. Permits TypeScript code to generate goog.module.declareLegacyNamespace code with TSMES.
    
    PiperOrigin-RevId: 436469265
    tsjs-language-eng authored and copybara-github committed Mar 22, 2022
    Copy the full SHA
    878f2f7 View commit details

Commits on Mar 29, 2022

  1. Fix the error message for TSMES to be more descriptive.

    PiperOrigin-RevId: 437974921
    tsjs-language-eng authored and copybara-github committed Mar 29, 2022
    Copy the full SHA
    e6cc4a8 View commit details

Commits on Apr 4, 2022

  1. Fix externs with imported symbols for .ts files

    Make Tsickle collect aliases for imported symbols during externs generation, even if the source file is a ".ts" file.
    
    PiperOrigin-RevId: 439258206
    frigus02 authored and copybara-github committed Apr 4, 2022
    Copy the full SHA
    ebf29db View commit details

Commits on Apr 5, 2022

  1. Fully specifies ReadonlyArray in closure externs.

    PiperOrigin-RevId: 439648356
    varomodt authored and copybara-github committed Apr 5, 2022
    Copy the full SHA
    68a7640 View commit details

Commits on Apr 6, 2022

  1. Add event map for EventSource

    This allow to define custom callback when processing http://go/mdn/API/Server-sent_events
    
    PiperOrigin-RevId: 439772006
    tsjs-language-eng authored and copybara-github committed Apr 6, 2022
    Copy the full SHA
    fcfc836 View commit details

Commits on Apr 7, 2022

  1. Upgrade TypeScript in google3 to version 4.6.3.

    This change flips the language & compiler version used for all google3
    compilations to version 4.6.3. See go/ts46upgrade for more information
    on the upgrade.
    
    PiperOrigin-RevId: 440175297
    tsjs-language-eng authored and copybara-github committed Apr 7, 2022
    Copy the full SHA
    cbe0662 View commit details

Commits on Apr 8, 2022

  1. Bump the TypeScript version to 4.6.3.

    This fixes the CI build after the breakage in cbe0662, which didn't adjust the TS version.
    
    PiperOrigin-RevId: 440315859
    mprobst authored and copybara-github committed Apr 8, 2022
    Copy the full SHA
    8f11720 View commit details
  2. Improve test result legibility by setting a background color.

    The symbols used to mark deletions and insertions are very subtle and hard to
    see in big diffs. Adding a splash of background color makes the test much more
    readable.
    
    The drawback is that this will likely print poorly in some environments (e.g.
    test results displayed in some browsers where the tool doesn't interpret
    console colors), but that still seems preferable to just the tiny [ ] markers.
    
    PiperOrigin-RevId: 440321079
    mprobst authored and copybara-github committed Apr 8, 2022
    Copy the full SHA
    383bf44 View commit details
  3. For externs: If we have no constructor, emit types from parent class …

    …constructors if present.
    
    PiperOrigin-RevId: 440356383
    tsjs-language-eng authored and copybara-github committed Apr 8, 2022
    Copy the full SHA
    efe8158 View commit details
  4. Upgrade a few deprecated TS compiler function calls.

    PiperOrigin-RevId: 440416543
    tsjs-language-eng authored and copybara-github committed Apr 8, 2022
    Copy the full SHA
    ee6985f View commit details
  5. Do not generate a module.id symbol if a top-level module symbol exist…

    …s in the source file.
    
    PiperOrigin-RevId: 440422774
    tsjs-language-eng authored and copybara-github committed Apr 8, 2022
    Copy the full SHA
    1cd5183 View commit details

Commits on Apr 11, 2022

  1. Adding @wizcallback into the allowed list of annotations

    PiperOrigin-RevId: 440887580
    tsjs-language-eng authored and copybara-github committed Apr 11, 2022
    Copy the full SHA
    daf0688 View commit details

Commits on Apr 13, 2022

  1. Update tsickle test to reflect the new TS 4.6 behavior.

    TS 4.6.3 introduced a behavior change not present in TS 4.6-beta in which it adds an unused import of an enum even though the enum value is no longer referenced (microsoft/TypeScript#48124)
    
    This CL updates the tsickle test which was originally intended to demonstrate the old behavior.
    
    PiperOrigin-RevId: 441534203
    rishipal authored and copybara-github committed Apr 13, 2022
    Copy the full SHA
    9d8bc76 View commit details

Commits on Apr 14, 2022

  1. Upgrade all dependencies.

    Using yarn upgrade --latest --save-dev.
    
    This required some minor changes to adjust to changed interfaces.
    mprobst committed Apr 14, 2022
    Copy the full SHA
    9f3c534 View commit details
  2. Upgrade all dependencies.

    Using yarn upgrade --latest --save-dev.
    
    This required some minor changes to adjust to changed interfaces.
    mprobst committed Apr 14, 2022
    Copy the full SHA
    71f28ff View commit details

Commits on Apr 20, 2022

  1. Fix typo in e2e tests

    KevinBoyette authored and mprobst committed Apr 20, 2022
    Copy the full SHA
    6183493 View commit details
  2. Merge pull request #1347 from angular:upg

    PiperOrigin-RevId: 441789297
    copybara-github committed Apr 20, 2022
    Copy the full SHA
    857bf2a View commit details
  3. Avoid multiple assignments to same exports property

    In certain cases, the typescript compiler produces more than
    one assignment to the same `exports.abc` property. Eliminate
    all but one of them to avoid JSC_EXPORT_REPEATED_ERROR errors
    in JSCompiler.
    
    PiperOrigin-RevId: 443168642
    mhausner authored and copybara-github committed Apr 20, 2022
    Copy the full SHA
    45082d1 View commit details

Commits on Apr 26, 2022

  1. Fix some deprecated TS API usages (and other lints)

    PiperOrigin-RevId: 444498976
    frigus02 authored and copybara-github committed Apr 26, 2022
    Copy the full SHA
    0ac1b59 View commit details

Commits on May 4, 2022

  1. Refactor remaining uses of deprecated TS APIs (and other lints)

    PiperOrigin-RevId: 446443214
    frigus02 authored and copybara-github committed May 4, 2022
    Copy the full SHA
    937295d View commit details

Commits on May 5, 2022

  1. Resolve import= aliases when printing closure types

    Given code like this:
    
        import Foo from '...';
        import Baz = Foo.Bar.Baz;
        let baz: Baz|undefined;
    
    Challenge: When printing the type for `baz`, the type checker resolves `Baz` to the local alias `Baz`. Tsickle needs to print a fully qualified name based on the requireType import, e.g. `tsickle_Foo_1.Bar.Baz`.
    
    Solution: Pass `ts.NodeBuilderFlags.UseOnlyExternalAliasing` to `typeChecker.symbolToEntityName`. Externs used to rely on the local alias for namespace imports and thus needed some fixes, too.
    
    The following solution was also considered: Resolve all aliases created by import= declarations manually and store them in the `symbolToAliasedNames` map. The flag is implemented here instead because the symbol/alias thing is a workaround in Tsickle and extending it doesn't feel like the right thing to do.
    
    PiperOrigin-RevId: 446651392
    frigus02 authored and copybara-github committed May 5, 2022
    Copy the full SHA
    0f2aceb View commit details

Commits on May 9, 2022

  1. Fix performance regression caused by many fs accesses

    A recent change in externs.ts caused a lot of unnecessary file system accesses,
    which could in certain scenarious massively slow down builds. This fixes the
    regression by making file system accesses only when necessary and reusing the
    results.
    
    PiperOrigin-RevId: 447453299
    frigus02 authored and copybara-github committed May 9, 2022
    Copy the full SHA
    260d867 View commit details
  2. Updates bazelOpts usage. replaces es5mode with devmode

    PiperOrigin-RevId: 447556332
    tsjs-language-eng authored and copybara-github committed May 9, 2022
    Copy the full SHA
    c0123da View commit details

Commits on May 11, 2022

  1. Add TemplateStringsArray and RegExpMatchArray to closure_externs.js.

    PiperOrigin-RevId: 447928946
    tsjs-language-eng authored and copybara-github committed May 11, 2022
    Copy the full SHA
    0e79979 View commit details

Commits on May 16, 2022

  1. Avoid adding requireType for symbols that are already imported.

    This should not make a semantic difference, but saves on some potential
    confusion and extraneous imports.
    
    PiperOrigin-RevId: 448907766
    mprobst authored and copybara-github committed May 16, 2022
    Copy the full SHA
    fdec72d View commit details

Commits on May 20, 2022

  1. Translate readonly to @const

    Annotate `readonly` class/interface properties as `@const`, so that Closure Compiler can enforce this for JavaScript dependents.
    
    PiperOrigin-RevId: 449930571
    frigus02 authored and copybara-github committed May 20, 2022
    Copy the full SHA
    d841bc0 View commit details

Commits on May 25, 2022

  1. Flag flip tsickle to use TypeScript 4.7.2

    PiperOrigin-RevId: 450901473
    tsjs-language-eng authored and copybara-github committed May 25, 2022
    Copy the full SHA
    0ef2c66 View commit details
  2. Copy the full SHA
    cefb49a View commit details

Commits on May 31, 2022

  1. Do not track yarn.lock so that we don't have any problems with having…

    … old dependencies living along while running yarn tests (#1365)
    h-joo authored May 31, 2022
    Copy the full SHA
    7962c23 View commit details

Commits on Jun 10, 2022

  1. Reformat compiler_host.ts, tsickle_test.ts, `fileoverview_comment…

    …_transformer.ts` and `decorator_downlevel_transformer_test.ts`
    
    Reformat these files to match the results from our current automated format tool.
    This is to prevent the noise from this change obscuring a fix that is to follow.
    
    PiperOrigin-RevId: 454052498
    tsjs-language-eng authored and copybara-github committed Jun 10, 2022
    Copy the full SHA
    1deca99 View commit details

Commits on Jun 16, 2022

  1. Bump TypeScript in tsickle to 4.7.2

    This was accidentally reverted in 1deca99.
    
    PiperOrigin-RevId: 455290993
    frigus02 authored and copybara-github committed Jun 16, 2022
    Copy the full SHA
    5ba8bdf View commit details
  2. Update TSMES JS generator to emit ES5-compatible code so it may be lo…

    …aded as-is with older browsers
    
    PiperOrigin-RevId: 455463892
    tsjs-language-eng authored and copybara-github committed Jun 16, 2022
    Copy the full SHA
    8df7016 View commit details

Commits on Jun 21, 2022

  1. Allow translation of string mapping types such as Uncapitalize.

    This will always result in a type of `string` regardless of the input types.
    
    PiperOrigin-RevId: 456317489
    tsjs-language-eng authored and copybara-github committed Jun 21, 2022
    Copy the full SHA
    0ba13ba View commit details

Commits on Jun 22, 2022

  1. Add a flag generateExtraSuppressions to stop adding auto-generated …

    …suppressions to tsickle output in tests.
    
    This is in preparation to lowering the @Suppress in tsickle output.
    
    PiperOrigin-RevId: 456614217
    tsjs-language-eng authored and copybara-github committed Jun 22, 2022
    Copy the full SHA
    e83542d View commit details

Commits on Jun 30, 2022

  1. Internal change

    PiperOrigin-RevId: 458248939
    tsjs-language-eng authored and copybara-github committed Jun 30, 2022
    Copy the full SHA
    3285e26 View commit details
  2. Automated rollback of commit 3285e26.

    PiperOrigin-RevId: 458269645
    tsjs-language-eng authored and copybara-github committed Jun 30, 2022
    Copy the full SHA
    4aaf327 View commit details

Commits on Jul 1, 2022

  1. Declaration merging for classes

    Implement support for merging declarations of classes and namespaces.
    - Add a tsickle transformer that transforms namespaces that merge declarations with a class.
    - Allows for nested classes and enum declarations.
    - The inner classes and enums are hoisted out of the namespace and a type alias is added to the outer class.
    - Correct JSDoc type annotations are generated for the inner classes and enums.
    - All references to inner classes and enums must be fully qualified with the name of the outer class.
    - The transformer is only used for ts_library targets that have the attribute "use_declaration_merging_transformation" set to True. The default for the attribute is False.
    
    PiperOrigin-RevId: 458401650
    mhausner authored and copybara-github committed Jul 1, 2022
    Copy the full SHA
    b50963c View commit details

Commits on Jul 7, 2022

  1. rel: 0.46.3.

    mprobst committed Jul 7, 2022
    Copy the full SHA
    eddd2b8 View commit details
Showing 437 changed files with 3,499 additions and 1,504 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
.vscode/
out/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -208,5 +208,5 @@ From the master branch run:
```
npm config set registry https://wombat-dressing-room.appspot.com
npm login
npm publish
npm publish # runs a clean build & test automatically
```
5 changes: 3 additions & 2 deletions demo/demo.ts
Original file line number Diff line number Diff line change
@@ -164,15 +164,16 @@ export function toClosureJS(
pathToModuleName: (context, fileName) =>
tsickle.pathToModuleName(rootModulePath, context, fileName),
fileNameToModuleId: (fileName) => path.relative(rootModulePath, fileName),
es5Mode: true,
googmodule: true,
transformDecorators: true,
transformTypesToClosure: true,
typeBlackListPaths: new Set(),
untyped: false,
logWarning: (warning) => console.error(ts.formatDiagnostics([warning], compilerHost)),
logWarning: (warning) =>
console.error(ts.formatDiagnostics([warning], compilerHost)),
options,
moduleResolutionHost: compilerHost,
generateExtraSuppressions: true,
};
const diagnostics = ts.getPreEmitDiagnostics(program);
if (diagnostics.length > 0) {
4 changes: 2 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@
"dependencies": {
"minimist": "^1.2.3",
"tsickle": "file:../",
"typescript": "h-joo/TypeScript#ts45-no-double-comments"
"typescript": "4.7.2"
},
"devDependencies": {
"@types/minimist": "1.2.0",
"@types/node": "^10.5.6"
},
"scripts": {
"build": "(cd ../ && yarn build) && node_modules/typescript/bin/tsc",
"build": "(cd ../ && yarn build) && tsc",
"demo": "node --preserve-symlinks build/demo.js -- --outDir `pwd`/tsickle-out"
}
}
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsickle",
"version": "0.46.0",
"version": "0.46.3",
"description": "Transpile TypeScript code to JavaScript with Closure annotations.",
"main": "out/src/tsickle.js",
"typings": "out/src/tsickle.d.ts",
@@ -11,30 +11,31 @@
"out/src/*"
],
"peerDependencies": {
"typescript": "h-joo/TypeScript#ts45-no-double-comments"
"typescript": "~4.7.2"
},
"devDependencies": {
"@types/diff-match-patch": "^1.0.32",
"@types/glob": "5.0.35",
"@types/jasmine": "^3.7.7",
"@types/node": "^10.5.6",
"@types/glob": "7.2.0",
"@types/jasmine": "^4.0.2",
"@types/node": "^17.0.24",
"@types/source-map-support": "^0.5.3",
"diff-match-patch": "^1.0.5",
"glob": "7.1.2",
"google-closure-compiler": "^20211006.0.0",
"jasmine": "^3.7.0",
"glob": "8.0.1",
"google-closure-compiler": "^20220405.0.0",
"jasmine": "^4.1.0",
"jasmine-node": "^3.0.0",
"source-map": "^0.7.3",
"source-map-support": "^0.5.19",
"tslib": "^2.2.0",
"tslint": "^6.1.3",
"typescript": "h-joo/TypeScript#ts45-no-double-comments"
"typescript": "4.7.2"
},
"scripts": {
"build": "tsc ",
"build": "tsc",
"clean": "rm -r out",
"lint": "tslint -c tslint.json -p tsconfig.json",
"test": "jasmine out/test/*.js && (cd demo && yarn && tsc) && npm run lint"
"test": "jasmine out/test/*.js && (cd demo && yarn && tsc) && yarn run lint",
"prepack": "yarn run clean && yarn run build && yarn run test"
},
"repository": {
"type": "git",
31 changes: 12 additions & 19 deletions src/closure_externs.js
Original file line number Diff line number Diff line change
@@ -52,26 +52,11 @@ var NodeListOf;
*/
var RegExpExecArray;

/**
* @record
* @template T
* @extends {Array<T>}
*/
function ReadonlyArray() {}
/** @typedef {!Map} */
var ReadonlyMap;

/**
* @constructor
* @template K, V
* @extends {Map<K, V>}
*/
function ReadonlyMap() {}

/**
* @constructor
* @template T
* @extends {Set<T>}
*/
function ReadonlySet() {}
/** @typedef {!Set} */
var ReadonlySet;

/**
* @record
@@ -110,6 +95,12 @@ function CryptoKeyPair() {};
/** @typedef {!{handleEvent: function(Event):void}} */
var EventListenerObject;

/** @typedef {!ITemplateArray} */
var TemplateStringsArray;

/** @typedef {!RegExpResult} */
var RegExpMatchArray;

/** @record */
function ImportMeta() {};

@@ -131,3 +122,5 @@ class WindowEventMap {}
class GlobalEventHandlersEventMap {}
/** @interface */
class DocumentAndElementEventHandlersEventMap {}
/** @interface */
class EventSourceEventMap {}
57 changes: 26 additions & 31 deletions src/clutz.ts
Original file line number Diff line number Diff line change
@@ -53,11 +53,11 @@ export function makeDeclarationTransformerFactory(
if (imports.length > 0) {
importStmts = imports.map(fileName => {
fileName = path.relative(options.rootDir!, fileName);
return ts.createImportDeclaration(
return ts.factory.createImportDeclaration(
/* decorators */ undefined,
/* modifiers */ undefined,
/* importClause */ undefined,
/* moduleSpecifier */ ts.createStringLiteral(fileName),
/* moduleSpecifier */ ts.factory.createStringLiteral(fileName),
);
});
}
@@ -70,7 +70,7 @@ export function makeDeclarationTransformerFactory(
// Only need to transform file if we needed one of the above additions.
if (!importStmts && !globalBlock) return file;

return ts.updateSourceFileNode(file, [
return ts.factory.updateSourceFile(file, [
...(importStmts ?? []),
...file.statements,
...(globalBlock ? [globalBlock] : []),
@@ -216,53 +216,50 @@ function generateClutzAliases(
const mangledName = `module$contents$${clutzModuleName}_${symbol.name}`;
// These ExportSpecifiers are the `foo as bar` bits as found in a larger
// `export {foo as bar}` statement, which is constructed after this loop.
globalExports.push(ts.createExportSpecifier(
/* isTypeOnly */ false, ts.createIdentifier(localName),
ts.createIdentifier(mangledName)));
nestedExports.push(ts.createExportSpecifier(
globalExports.push(ts.factory.createExportSpecifier(
/* isTypeOnly */ false, ts.factory.createIdentifier(localName),
ts.factory.createIdentifier(mangledName)));
nestedExports.push(ts.factory.createExportSpecifier(
/* isTypeOnly */ false,
localName === symbol.name ? undefined : localName,
ts.createIdentifier(symbol.name)));
ts.factory.createIdentifier(symbol.name)));
}

// Create two export statements that will be used to contribute to the
// ಠ_ಠ.clutz namespace.
const globalDeclarations: ts.Statement[] = [
// 1) For globalExports,
// export {...};
ts.createExportDeclaration(
ts.factory.createExportDeclaration(
/* decorators */ undefined,
/* modifiers */ undefined,
ts.createNamedExports(globalExports),
),
/* isTypeOnly */ false, ts.factory.createNamedExports(globalExports)),
// 2) For nestedExports
// namespace module$exports$module$name$here {
// export {...};
// }
ts.createModuleDeclaration(
ts.factory.createModuleDeclaration(
/* decorators */ undefined,
/* modifiers */[ts.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.createIdentifier(`module$exports$${clutzModuleName}`),
ts.createModuleBlock([
ts.createExportDeclaration(
/* modifiers */[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)],
ts.factory.createIdentifier(`module$exports$${clutzModuleName}`),
ts.factory.createModuleBlock([
ts.factory.createExportDeclaration(
/* decorators */ undefined,
/* modifiers */ undefined,
ts.createNamedExports(nestedExports),
),
/* isTypeOnly */ false,
ts.factory.createNamedExports(nestedExports)),
]),
ts.NodeFlags.Namespace,
),
ts.NodeFlags.Namespace),
];


// Wrap a `declare global { namespace ಠ_ಠ.clutz { ... } }` around
// the statements in globalDeclarations.
return ts.createModuleDeclaration(
return ts.factory.createModuleDeclaration(
/* decorators */ undefined,
/* modifiers */[ts.createModifier(ts.SyntaxKind.DeclareKeyword)],
ts.createIdentifier('global'),
ts.createModuleBlock([
ts.createModuleDeclaration(
/* modifiers */[ts.factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
ts.factory.createIdentifier('global'), ts.factory.createModuleBlock([
ts.factory.createModuleDeclaration(
/* decorators */ undefined,
/* modifiers */ undefined,
// Note: it's not exactly right to use a '.' within an identifier
@@ -271,13 +268,11 @@ function generateClutzAliases(
// ModuleDeclaration, but nesting another ModuleDeclaration in here
// always created a new {} block, despite trying the
// 'NestedNamespace' flag.
ts.createIdentifier('ಠ_ಠ.clutz'),
ts.createModuleBlock(globalDeclarations),
ts.NodeFlags.Namespace | ts.NodeFlags.NestedNamespace,
),
ts.factory.createIdentifier('ಠ_ಠ.clutz'),
ts.factory.createModuleBlock(globalDeclarations),
ts.NodeFlags.Namespace | ts.NodeFlags.NestedNamespace),
]),
ts.NodeFlags.GlobalAugmentation,
);
ts.NodeFlags.GlobalAugmentation);
}

/**
44 changes: 26 additions & 18 deletions src/decorators.ts
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ export function transformDecoratorsOutputForClosurePropertyRenaming(diagnostics:
const result: ts.Transformer<ts.SourceFile> = (sourceFile: ts.SourceFile) => {
let nodeNeedingGoogReflect: undefined|ts.Node = undefined;
const visitor: ts.Visitor = (node) => {
const replacementNode = rewriteDecorator(node, context);
const replacementNode = rewriteDecorator(node);
if (replacementNode) {
nodeNeedingGoogReflect = node;
return replacementNode;
@@ -113,16 +113,19 @@ export function transformDecoratorsOutputForClosurePropertyRenaming(diagnostics:
'Internal tsickle error: could not find goog.module statement to import __tsickle_googReflect for decorator compilation.');
return sourceFile;
}
const googRequireReflectObjectProperty = ts.createVariableStatement(
undefined,
ts.createVariableDeclarationList(
[ts.createVariableDeclaration(
'__tsickle_googReflect', undefined,

ts.createCall(
ts.createPropertyAccess(ts.createIdentifier('goog'), 'require'), undefined,
[ts.createStringLiteral('goog.reflect')]))],
ts.NodeFlags.Const));
const googRequireReflectObjectProperty =
ts.factory.createVariableStatement(
undefined,
ts.factory.createVariableDeclarationList(
[ts.factory.createVariableDeclaration(
'__tsickle_googReflect',
/* exclamationToken */ undefined, /* type */ undefined,
ts.factory.createCallExpression(
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier('goog'), 'require'),
undefined,
[ts.factory.createStringLiteral('goog.reflect')]))],
ts.NodeFlags.Const));
// The boilerplate we produce has a goog.module line, then two related
// lines dealing with the `module` variable. Insert our goog.require
// after that to avoid visually breaking up the module info, and to be
@@ -131,7 +134,8 @@ export function transformDecoratorsOutputForClosurePropertyRenaming(diagnostics:
updatedSourceFile = ts.factory.updateSourceFile(
updatedSourceFile,
ts.setTextRange(
ts.createNodeArray(statements), updatedSourceFile.statements),
ts.factory.createNodeArray(statements),
updatedSourceFile.statements),
updatedSourceFile.isDeclarationFile,
updatedSourceFile.referencedFiles,
updatedSourceFile.typeReferenceDirectives,
@@ -151,7 +155,7 @@ export function transformDecoratorsOutputForClosurePropertyRenaming(diagnostics:
*
* Returns undefined if no modification is necessary.
*/
function rewriteDecorator(node: ts.Node, context: ts.TransformationContext): ts.Node|undefined {
function rewriteDecorator(node: ts.Node): ts.Node|undefined {
if (!ts.isCallExpression(node)) {
return;
}
@@ -178,10 +182,14 @@ function rewriteDecorator(node: ts.Node, context: ts.TransformationContext): ts.
return;
}
const fieldNameLiteral = untypedFieldNameLiteral;
args[2] = ts.createCall(
ts.createPropertyAccess(ts.createIdentifier('__tsickle_googReflect'), 'objectProperty'),
undefined, [ts.createStringLiteral(fieldNameLiteral.text), ts.getMutableClone(args[1])]);
return ts.updateCall(node, node.expression, node.typeArguments, args);
args[2] = ts.factory.createCallExpression(
ts.factory.createPropertyAccessExpression(
ts.factory.createIdentifier('__tsickle_googReflect'),
'objectProperty'),
undefined,
[ts.factory.createStringLiteral(fieldNameLiteral.text), args[1]]);
return ts.factory.updateCallExpression(
node, node.expression, node.typeArguments, args);
}

function isGoogModuleStatement(statement: ts.Node) {
@@ -235,7 +243,7 @@ function sanitizeDecorateComments(comments: ts.SynthesizedComment[]):
*/
export function transformDecoratorJsdoc():
ts.TransformerFactory<ts.SourceFile> {
return (context: ts.TransformationContext) => {
return () => {
const transformer: ts.Transformer<ts.SourceFile> =
(sourceFile: ts.SourceFile) => {
for (const stmt of sourceFile.statements) {
Loading