@polymer/gen-typescript-declarations
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -9,2 +9,6 @@ # Changelog | ||
## [1.1.2] - 2018-02-08 | ||
- Elements that are constructable (usually a call to the Polymer function whose result is assigned to some variable) can now have behaviors. | ||
- The `--deleteExisting` command line flag will no longer delete `.d.ts` files that are referenced as values in the `addReferences` config option, since such files are typically hand-written. | ||
## [1.1.1] - 2018-02-05 | ||
@@ -11,0 +15,0 @@ - Fix missing `glob` dependency. |
@@ -58,3 +58,4 @@ "use strict"; | ||
description: 'Recursively delete all .d.ts files in <outDir> before ' + | ||
'writing new typings, excluding node_modules/ bower_components/.', | ||
'writing new typings, excluding node_modules/, bower_components/, ' + | ||
'or any file added using the <addReferences> config option.', | ||
}, | ||
@@ -98,3 +99,3 @@ ]; | ||
if (args.deleteExisting) { | ||
const dtsFiles = glob.sync('**/*.d.ts', { | ||
let dtsFiles = glob.sync('**/*.d.ts', { | ||
cwd: args.outDir, | ||
@@ -108,2 +109,12 @@ absolute: true, | ||
}); | ||
// If the addReferences option is being used, it's probably to add some | ||
// manually written typings. Since manually written typing files won't get | ||
// re-generated, we shouldn't delete them. | ||
const dontDelete = new Set(); | ||
for (const refs of Object.values(config.addReferences || {})) { | ||
for (const ref of refs) { | ||
dontDelete.add(path.resolve(args.root, ref)); | ||
} | ||
} | ||
dtsFiles = dtsFiles.filter((filepath) => !dontDelete.has(filepath)); | ||
console.log(`Deleting ${dtsFiles.length} existing d.ts files from ` + | ||
@@ -110,0 +121,0 @@ `${path.resolve(args.outDir)}`); |
@@ -235,5 +235,7 @@ "use strict"; | ||
} | ||
const behaviors = isPolymerElement(feature) ? | ||
feature.behaviorAssignments.map((behavior) => behavior.name) : | ||
[]; | ||
if (constructable) { | ||
// TODO How do we handle behaviors with classes? | ||
const c = new ts.Class({ | ||
parent.members.push(new ts.Class({ | ||
name: shortName, | ||
@@ -249,4 +251,14 @@ description: feature.description || feature.summary, | ||
] | ||
}); | ||
parent.members.push(c); | ||
})); | ||
if (behaviors.length > 0) { | ||
// We need to augment our class declaration with some behaviors. Behaviors | ||
// are interfaces, so our class can't directly extend them, like we can do | ||
// with mixin functions. However, the class declaration implicitly creates | ||
// a corresponding interface with the same name, and we can augment that | ||
// with the behavior interfaces using declaration merging. | ||
parent.members.push(new ts.Interface({ | ||
name: shortName, | ||
extends: behaviors, | ||
})); | ||
} | ||
} | ||
@@ -268,3 +280,3 @@ else { | ||
i.extends.push('Polymer.Element'); | ||
i.extends.push(...feature.behaviorAssignments.map((behavior) => behavior.name)); | ||
i.extends.push(...behaviors); | ||
} | ||
@@ -271,0 +283,0 @@ parent.members.push(i); |
{ | ||
"name": "@polymer/gen-typescript-declarations", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Generate TypeScript type declarations for Polymer components.", | ||
@@ -5,0 +5,0 @@ "main": "lib/gen-ts.js", |
@@ -53,3 +53,4 @@ /** | ||
description: 'Recursively delete all .d.ts files in <outDir> before ' + | ||
'writing new typings, excluding node_modules/ bower_components/.', | ||
'writing new typings, excluding node_modules/, bower_components/, ' + | ||
'or any file added using the <addReferences> config option.', | ||
}, | ||
@@ -108,3 +109,3 @@ ]; | ||
if (args.deleteExisting) { | ||
const dtsFiles = glob.sync('**/*.d.ts', { | ||
let dtsFiles = glob.sync('**/*.d.ts', { | ||
cwd: args.outDir, | ||
@@ -118,2 +119,14 @@ absolute: true, | ||
}); | ||
// If the addReferences option is being used, it's probably to add some | ||
// manually written typings. Since manually written typing files won't get | ||
// re-generated, we shouldn't delete them. | ||
const dontDelete = new Set<string>(); | ||
for (const refs of Object.values(config.addReferences || {})) { | ||
for (const ref of refs) { | ||
dontDelete.add(path.resolve(args.root, ref)); | ||
} | ||
} | ||
dtsFiles = dtsFiles.filter((filepath) => !dontDelete.has(filepath)); | ||
console.log( | ||
@@ -120,0 +133,0 @@ `Deleting ${dtsFiles.length} existing d.ts files from ` + |
@@ -294,5 +294,8 @@ /** | ||
const behaviors = isPolymerElement(feature) ? | ||
feature.behaviorAssignments.map((behavior) => behavior.name) : | ||
[]; | ||
if (constructable) { | ||
// TODO How do we handle behaviors with classes? | ||
const c = new ts.Class({ | ||
parent.members.push(new ts.Class({ | ||
name: shortName, | ||
@@ -308,5 +311,16 @@ description: feature.description || feature.summary, | ||
] | ||
}); | ||
parent.members.push(c); | ||
})); | ||
if (behaviors.length > 0) { | ||
// We need to augment our class declaration with some behaviors. Behaviors | ||
// are interfaces, so our class can't directly extend them, like we can do | ||
// with mixin functions. However, the class declaration implicitly creates | ||
// a corresponding interface with the same name, and we can augment that | ||
// with the behavior interfaces using declaration merging. | ||
parent.members.push(new ts.Interface({ | ||
name: shortName, | ||
extends: behaviors, | ||
})); | ||
} | ||
} else { | ||
@@ -328,4 +342,3 @@ // TODO How do we handle mixins when we are emitting an interface? We don't | ||
i.extends.push('Polymer.Element'); | ||
i.extends.push(...feature.behaviorAssignments.map( | ||
(behavior) => behavior.name)); | ||
i.extends.push(...behaviors); | ||
} | ||
@@ -332,0 +345,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190852
3787