compatfactory
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,7 @@ | ||
## [0.0.2](https://github.com/wessberg/compatfactory/compare/v0.0.1...v0.0.2) (2021-05-28) | ||
### Features | ||
- unify signatures for createImportEqualsDeclaration and createMappedTypeNode with latest TypeScript versions for v4.0 and v4.1 ([a4e3f5f](https://github.com/wessberg/compatfactory/commit/a4e3f5f9b04108f0c1d188ed6a3d5eff689aff09)) | ||
## 0.0.1 (2021-05-28) |
@@ -6,6 +6,6 @@ "use strict"; | ||
if ("factory" in factoryLike && factoryLike.factory != null) { | ||
return factoryLike.factory; | ||
return normalizeNodeFactory(factoryLike.factory); | ||
} | ||
else if (!("updateSourceFileNode" in factoryLike)) { | ||
return factoryLike; | ||
return normalizeNodeFactory(factoryLike); | ||
} | ||
@@ -15,2 +15,25 @@ return createNodeFactory(factoryLike); | ||
exports.ensureNodeFactory = ensureNodeFactory; | ||
function normalizeNodeFactory(factory) { | ||
const needsModifications = factory.createImportEqualsDeclaration.length === 4 || factory.createMappedTypeNode.length === 4; | ||
if (needsModifications) { | ||
return { | ||
...factory, | ||
...(factory.createImportEqualsDeclaration.length === 4 | ||
? { | ||
createImportEqualsDeclaration(decorators, modifiers, isTypeOnly, name, moduleReference) { | ||
return factory.createImportEqualsDeclaration(decorators, modifiers, name, moduleReference); | ||
} | ||
} | ||
: {}), | ||
...(factory.createMappedTypeNode.length === 4 | ||
? { | ||
createMappedTypeNode(readonlyToken, typeParameter, nameType, questionToken, type) { | ||
return factory.createMappedTypeNode(readonlyToken, typeParameter, questionToken, type); | ||
} | ||
} | ||
: {}) | ||
}; | ||
} | ||
return factory; | ||
} | ||
function createNodeFactory(typescript) { | ||
@@ -17,0 +40,0 @@ function createToken(token) { |
export function ensureNodeFactory(factoryLike) { | ||
if ("factory" in factoryLike && factoryLike.factory != null) { | ||
return factoryLike.factory; | ||
return normalizeNodeFactory(factoryLike.factory); | ||
} | ||
else if (!("updateSourceFileNode" in factoryLike)) { | ||
return factoryLike; | ||
return normalizeNodeFactory(factoryLike); | ||
} | ||
return createNodeFactory(factoryLike); | ||
} | ||
function normalizeNodeFactory(factory) { | ||
const needsModifications = factory.createImportEqualsDeclaration.length === 4 || factory.createMappedTypeNode.length === 4; | ||
if (needsModifications) { | ||
return { | ||
...factory, | ||
...(factory.createImportEqualsDeclaration.length === 4 | ||
? { | ||
createImportEqualsDeclaration(decorators, modifiers, isTypeOnly, name, moduleReference) { | ||
return factory.createImportEqualsDeclaration(decorators, modifiers, name, moduleReference); | ||
} | ||
} | ||
: {}), | ||
...(factory.createMappedTypeNode.length === 4 | ||
? { | ||
createMappedTypeNode(readonlyToken, typeParameter, nameType, questionToken, type) { | ||
return factory.createMappedTypeNode(readonlyToken, typeParameter, questionToken, type); | ||
} | ||
} | ||
: {}) | ||
}; | ||
} | ||
return factory; | ||
} | ||
function createNodeFactory(typescript) { | ||
@@ -11,0 +34,0 @@ function createToken(token) { |
{ | ||
"name": "compatfactory", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A library that unifies the TypeScript Compiler API factory functions across all versions of TypeScript and makes them conform with the Node Factory API", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -38,3 +38,3 @@ <!-- SHADOW_SECTION_LOGO_START --> | ||
This library provides a little helper function, `ensureNodeFactory`, which takes a `NodeFactory` or a typescript object, and then returns an object conforming to the `NodeFactory` interface. | ||
In case a `NodeFactory` is passed to it, or if one could be found via the `typescript.factory` property, it will simply return the existing one with no further edits. For older TypeScript versions, it will | ||
In case a `NodeFactory` is passed to it, or if one could be found via the `typescript.factory` property, it will patch any inconsistencies there may be between the signatures of the factory functions across TypeScript versions and most often simply return the existing one with no further edits. For older TypeScript versions, it will | ||
wrap its factory functions with the new API such that you can simply use one API for all your operations. | ||
@@ -41,0 +41,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
151276
1402