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.41.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.42.0
Choose a head ref
  • 4 commits
  • 7 files changed
  • 3 contributors

Commits on Jun 14, 2021

  1. Repair the tsickle demo.

    We forgot to publish an updated version that works after the latest API
    changes.
    
    This change moves demo to a new release that's compatible, adjusts its
    TypeScript & tsickle version, and also includes its basic build in the
    yarn test target (that, independently, we might want to break into
    smaller tasks at some point).
    
    It also fixes an incorrect argument in the release instructions.
    mprobst committed Jun 14, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e5d941c View commit details

Commits on Jun 15, 2021

  1. Merge pull request #1273 from angular:demo-rel

    PiperOrigin-RevId: 379430084
    copybara-github committed Jun 15, 2021
    Copy the full SHA
    9b02ea4 View commit details
  2. Add support for optional method declarations.

    Optional method declarations are not handled like methods, as there is no way
    to declare methods as optional in Closure Compiler. Instead, these map to
    properties that have a function type.
    
    PiperOrigin-RevId: 379450936
    mprobst authored and copybara-github committed Jun 15, 2021
    Copy the full SHA
    ca1acb7 View commit details
  3. rel: 0.42.0

    mprobst committed Jun 15, 2021
    Copy the full SHA
    35705bd View commit details
Showing with 90 additions and 44 deletions.
  1. +1 −1 README.md
  2. +2 −2 demo/package.json
  3. +15 −29 demo/yarn.lock
  4. +2 −2 package.json
  5. +23 −10 src/jsdoc_transformer.ts
  6. +31 −0 test_files/optional_method/optional_method.js
  7. +16 −0 test_files/optional_method/optional_method.ts
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 -- --registry https://wombat-dressing-room.appspot.com
npm publish
```
4 changes: 2 additions & 2 deletions demo/package.json
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@
},
"dependencies": {
"minimist": "^1.2.3",
"tsickle": "^0.37.0",
"typescript": "~3.5.3"
"tsickle": "^0.41.0",
"typescript": "~4.3"
},
"devDependencies": {
"@types/minimist": "1.2.0",
44 changes: 15 additions & 29 deletions demo/yarn.lock
Original file line number Diff line number Diff line change
@@ -7,43 +7,29 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=

"@types/minimist@^1.2.1":
version "1.2.1"
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==

"@types/node@^10.5.6":
version "10.14.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.18.tgz#b7d45fc950e6ffd7edc685e890d13aa7b8535dce"
integrity sha512-ryO3Q3++yZC/+b8j8BdKd/dn9JlzlHBPdm80656xwYUdmPkpTGTjkAdt6BByiNupGPE8w0FhBgvYy/fX9hRNGQ==

minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=

minimist@^1.2.0, minimist@^1.2.3:
minimist@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.3.tgz#3db5c0765545ab8637be71f333a104a965a9ca3f"
integrity sha512-+bMdgqjMN/Z77a6NlY/I3U5LlRDbnmaAk6lDveAPKwSpcPM4tKAuYsvYF8xjhOPXhOYGe/73vVLVez5PW+jqhw==

mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
dependencies:
minimist "0.0.8"

source-map@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==

tsickle@^0.37.0:
version "0.37.0"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.37.0.tgz#cc8a174310ac349913c62477b346db4f342c87d1"
integrity sha512-ufUZqLUNqh+kOfr52N/hJ5JbiDO32/CO7ZCteZBX9HA2kiejwEgDaJeJe1GAj2TIu683IgTA/LPKvlns6Liw0w==
tsickle@^0.41.0:
version "0.41.0"
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.41.0.tgz#ab4f168a7168db6ce8fcdd306a44fa07270368ee"
integrity sha512-IRfRP3efl6E19MxqOwkty/hoqudAxd91tO75VmIZqXtVeiDyi3l3b8OqrC0/JagnJvqe+fHyefM5cbMR2lyEjw==
dependencies:
minimist "^1.2.0"
mkdirp "^0.5.1"
source-map "^0.7.3"
"@types/minimist" "^1.2.1"

typescript@~3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.3.tgz#c830f657f93f1ea846819e929092f5fe5983e977"
integrity sha512-ACzBtm/PhXBDId6a6sDJfroT2pOWt/oOnk4/dElG5G33ZL776N3Y6/6bKZJBFpd+b05F3Ct9qDjMeJmRWtE2/g==
typescript@~4.3:
version "4.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsickle",
"version": "0.41.0",
"version": "0.42.0",
"description": "Transpile TypeScript code to JavaScript with Closure annotations.",
"main": "out/src/tsickle.js",
"typings": "out/src/tsickle.d.ts",
@@ -34,7 +34,7 @@
"build": "tsc ",
"clean": "rm -r out",
"lint": "tslint -c tslint.json -p tsconfig.json",
"test": "jasmine out/test/*.js && npm run lint"
"test": "jasmine out/test/*.js && (cd demo && yarn && tsc) && npm run lint"
},
"repository": {
"type": "git",
33 changes: 23 additions & 10 deletions src/jsdoc_transformer.ts
Original file line number Diff line number Diff line change
@@ -189,15 +189,18 @@ function createMemberTypeDeclaration(
// Gather parameter properties from the constructor, if it exists.
const ctors: ts.ConstructorDeclaration[] = [];
let paramProps: ts.ParameterDeclaration[] = [];
const nonStaticProps: Array<ts.PropertyDeclaration|ts.PropertySignature> = [];
const staticProps: Array<ts.PropertyDeclaration|ts.PropertySignature> = [];
const nonStaticProps: ClosureProperty[] = [];
const staticProps: ClosureProperty[] = [];
const unhandled: ts.NamedDeclaration[] = [];
const abstractMethods: ts.FunctionLikeDeclaration[] = [];
for (const member of typeDecl.members) {
if (member.kind === ts.SyntaxKind.Constructor) {
ctors.push(member as ts.ConstructorDeclaration);
} else if (ts.isPropertyDeclaration(member) || ts.isPropertySignature(member)) {
const isStatic = transformerUtil.hasModifierFlag(member, ts.ModifierFlags.Static);
} else if (
ts.isPropertyDeclaration(member) || ts.isPropertySignature(member) ||
(ts.isMethodDeclaration(member) && member.questionToken)) {
const isStatic =
transformerUtil.hasModifierFlag(member, ts.ModifierFlags.Static);
if (isStatic) {
staticProps.push(member);
} else {
@@ -206,13 +209,16 @@ function createMemberTypeDeclaration(
} else if (
member.kind === ts.SyntaxKind.MethodDeclaration ||
member.kind === ts.SyntaxKind.MethodSignature ||
member.kind === ts.SyntaxKind.GetAccessor || member.kind === ts.SyntaxKind.SetAccessor) {
member.kind === ts.SyntaxKind.GetAccessor ||
member.kind === ts.SyntaxKind.SetAccessor) {
if (transformerUtil.hasModifierFlag(member, ts.ModifierFlags.Abstract) ||
ts.isInterfaceDeclaration(typeDecl)) {
abstractMethods.push(
member as ts.MethodDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration);
member as ts.MethodDeclaration | ts.GetAccessorDeclaration |
ts.SetAccessorDeclaration);
}
// Non-abstract methods only exist on classes, and are handled in regular emit.
// Non-abstract methods only exist on classes, and are handled in regular
// emit.
} else {
unhandled.push(member);
}
@@ -266,7 +272,7 @@ function createMemberTypeDeclaration(
}
const {tags, parameterNames} = mtt.getFunctionTypeJSDoc([fnDecl], []);
if (hasExportingDecorator(fnDecl, mtt.typeChecker)) tags.push({tagName: 'export'});
// Use element access instead of property access for compued names.
// Use element access instead of property access for computed names.
const lhs = typeof name === 'string' ? ts.createPropertyAccess(instancePropAccess, name) :
ts.createElementAccess(instancePropAccess, name);
// memberNamespace because abstract methods cannot be static in TypeScript.
@@ -321,9 +327,16 @@ export function escapeForComment(str: string): string {
return str.replace(/\/\*/g, '__').replace(/\*\//g, '__');
}

/**
* A kind of property declaration that tsickle generates a Closure property
* declaration for. Note that this includes ts.MethodDeclarations but only for
* optional methods.
*/
type ClosureProperty = ts.PropertyDeclaration|ts.PropertySignature|
ts.ParameterDeclaration|ts.MethodDeclaration;

function createClosurePropertyDeclaration(
mtt: ModuleTypeTranslator, expr: ts.Expression,
prop: ts.PropertyDeclaration|ts.PropertySignature|ts.ParameterDeclaration,
mtt: ModuleTypeTranslator, expr: ts.Expression, prop: ClosureProperty,
optional: boolean): ts.Statement {
const name = propertyName(prop);
if (!name) {
31 changes: 31 additions & 0 deletions test_files/optional_method/optional_method.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @fileoverview added by tsickle
* Generated from: test_files/optional_method/optional_method.ts
* @suppress {checkTypes,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
goog.module('test_files.optional_method.optional_method');
var module = module || { id: 'test_files/optional_method/optional_method.ts' };
goog.require('tslib');
// This test ensures that we generate declarations for optional methods (note
// the ?). Optional methods need special treatment, as they map to property
// declarations in Closure Compiler.
class OptionalMethod {
}
/* istanbul ignore if */
if (false) {
/** @type {(undefined|function(): void)} */
OptionalMethod.staticOptionalMethod;
/** @type {(undefined|function(): void)} */
OptionalMethod.prototype.optionalMethod;
}
// For comparison, these should generate the same type signatures as the
// following declarations.
class OptionalArrowFnProperty {
}
/* istanbul ignore if */
if (false) {
/** @type {(undefined|function(): void)} */
OptionalArrowFnProperty.staticArrowFnProperty;
/** @type {(undefined|function(): void)} */
OptionalArrowFnProperty.prototype.arrowFnProperty;
}
16 changes: 16 additions & 0 deletions test_files/optional_method/optional_method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export {};

// This test ensures that we generate declarations for optional methods (note
// the ?). Optional methods need special treatment, as they map to property
// declarations in Closure Compiler.
class OptionalMethod {
optionalMethod?(): void;
static staticOptionalMethod?(): void;
}

// For comparison, these should generate the same type signatures as the
// following declarations.
class OptionalArrowFnProperty {
arrowFnProperty?: () => void;
static staticArrowFnProperty?(): void;
}