babel-plugin-typescript-to-flow
Advanced tools
Comparing version 0.11.2 to 0.11.3
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -25,19 +25,9 @@ return result; | ||
const t = __importStar(require("@babel/types")); | ||
const convertTSTypeParameterInstantiation_1 = require("../converters/convertTSTypeParameterInstantiation"); | ||
const convertTSEntityName_1 = require("../converters/convertTSEntityName"); | ||
const convertTSTypeParameterDeclaration_1 = require("../converters/convertTSTypeParameterDeclaration"); | ||
const convertTSType_1 = require("../converters/convertTSType"); | ||
const convertFunctionTypeAnnotation_1 = require("../converters/convertFunctionTypeAnnotation"); | ||
const convertKey_1 = require("../converters/convertKey"); | ||
function convertMemberExpressionToQualifiedTypeIdentifier(id) { | ||
if (t.isIdentifier(id)) | ||
return id; | ||
if (!t.isIdentifier(id.object) && !t.isMemberExpression(id.object)) { | ||
throw new Error('not implemented'); | ||
} | ||
if (!t.isIdentifier(id.property)) { | ||
throw new Error('not implemented'); | ||
} | ||
return t.qualifiedTypeIdentifier(id.property, convertMemberExpressionToQualifiedTypeIdentifier(id.object)); | ||
} | ||
const convertTSTypeParameterInstantiation_1 = require("./convertTSTypeParameterInstantiation"); | ||
const convertTSEntityName_1 = require("./convertTSEntityName"); | ||
const convertTSTypeParameterDeclaration_1 = require("./convertTSTypeParameterDeclaration"); | ||
const convertTSType_1 = require("./convertTSType"); | ||
const convertFunctionTypeAnnotation_1 = require("./convertFunctionTypeAnnotation"); | ||
const convertKey_1 = require("./convertKey"); | ||
const convertMemberExpressionToQualifiedTypeIdentifier_1 = require("./convertMemberExpressionToQualifiedTypeIdentifier"); | ||
function convertClassTypeDeclaration(node) { | ||
@@ -63,3 +53,3 @@ const id = node.id; | ||
_extends = [ | ||
t.interfaceExtends(convertMemberExpressionToQualifiedTypeIdentifier(node.superClass), node.superTypeParameters | ||
t.interfaceExtends(convertMemberExpressionToQualifiedTypeIdentifier_1.convertMemberExpressionToQualifiedTypeIdentifier(node.superClass), node.superTypeParameters | ||
? convertTSTypeParameterInstantiation_1.convertTSTypeParameterInstantiation(node.superTypeParameters) | ||
@@ -97,3 +87,8 @@ : null), | ||
// @ts-ignore | ||
key, t.functionTypeAnnotation(typeParams, parameters, rest, returnType ? returnType : t.anyTypeAnnotation())); | ||
key, t.functionTypeAnnotation(typeParams, parameters, rest, returnType | ||
? returnType | ||
: t.isIdentifier(key) && key.name === 'constructor' | ||
? // special case - constructor type should have return type | ||
t.genericTypeAnnotation(t.identifier(id.name)) | ||
: t.anyTypeAnnotation())); | ||
prop.static = member.static; | ||
@@ -100,0 +95,0 @@ prop.kind = |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -267,3 +267,10 @@ return result; | ||
const elementTypes = node.elementTypes; | ||
return t.tupleTypeAnnotation(elementTypes.map(convertTSType)); | ||
return t.tupleTypeAnnotation(elementTypes.map(element => { | ||
if (t.isTSNamedTupleMember(element)) { | ||
return convertTSType(element.elementType); | ||
} | ||
else { | ||
return convertTSType(element); | ||
} | ||
})); | ||
} | ||
@@ -270,0 +277,0 @@ if (t.isTSObjectKeyword(node)) { |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -29,2 +29,3 @@ return result; | ||
if (elementPath.isClassMethod()) { | ||
// todo: | ||
///transformFunctionParams(elementPath.get('params')); | ||
@@ -31,0 +32,0 @@ } |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
import * as t from '@babel/types'; | ||
import { NodePath } from '@babel/traverse'; | ||
export declare function ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>): void; | ||
import { PluginPass } from '../types'; | ||
export declare function ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>, state: PluginPass): void; | ||
//# sourceMappingURL=ExportDefaultDeclaration.d.ts.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -27,4 +27,7 @@ return result; | ||
const convertFunctionTypeAnnotation_1 = require("../converters/convertFunctionTypeAnnotation"); | ||
function ExportDefaultDeclaration(path) { | ||
const convertClassTypeDeclaration_1 = require("../converters/convertClassTypeDeclaration"); | ||
function ExportDefaultDeclaration(path, state) { | ||
var _a; | ||
if (!state.opts.isAmbientContext) | ||
return; | ||
const srcDeclaration = path.node.declaration; | ||
@@ -40,4 +43,8 @@ if (t.isTSDeclareFunction(srcDeclaration)) { | ||
} | ||
else if (t.isClassDeclaration(srcDeclaration)) { | ||
const replacement = t.declareExportDeclaration(convertClassTypeDeclaration_1.convertClassTypeDeclaration(srcDeclaration)); | ||
replaceWith_1.replaceWith(path, replacement); | ||
} | ||
} | ||
exports.ExportDefaultDeclaration = ExportDefaultDeclaration; | ||
//# sourceMappingURL=ExportDefaultDeclaration.js.map |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -20,0 +20,0 @@ return result; |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.11.2", | ||
"version": "0.11.3", | ||
"scripts": { | ||
@@ -32,17 +32,22 @@ "cover": "jest --coverage", | ||
"@babel/template": "^7.10.4", | ||
"@babel/traverse": "^7.10.4", | ||
"@babel/types": "^7.10.4" | ||
"@babel/traverse": "^7.11.5", | ||
"@babel/types": "^7.11.5" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-proposal-class-properties": "^7.10.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.11.0", | ||
"@babel/preset-env": "^7.11.5", | ||
"@babel/preset-typescript": "^7.10.4", | ||
"@types/babel__traverse": "7.0.13", | ||
"@types/jest": "^26.0.3", | ||
"@types/babel__traverse": "7.0.15", | ||
"@types/jest": "^26.0.14", | ||
"@typescript-eslint/eslint-plugin": "^4.3.0", | ||
"@typescript-eslint/parser": "^4.3.0", | ||
"@zxbodya/recast": "^0.18.9", | ||
"codecov": "^3.7.0", | ||
"jest": "^26.1.0", | ||
"eslint": "^7.10.0", | ||
"eslint-config-prettier": "^6.12.0", | ||
"jest": "^26.4.2", | ||
"prettier": "^2.1.2", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^3.9.6" | ||
"typescript": "^4.0.3" | ||
}, | ||
@@ -55,3 +60,3 @@ "jest": { | ||
}, | ||
"gitHead": "950d353ab20bafcef431d6da0a9d1c1ad174c025" | ||
"gitHead": "13471285329207d9aa09d7f636f0334263e2a71e" | ||
} |
@@ -7,2 +7,23 @@ # babel-plugin-typescript-to-flow | ||
## Usage | ||
Most convenient - via `tsflow` utility, which currently is part of [flowts](https://github.com/zxbodya/flowts). | ||
## Usage as babel plugin: | ||
Installation: | ||
``` | ||
npm install babel-plugin-typescript-to-flow | ||
``` | ||
Plugin options: | ||
``` | ||
{ | ||
// should be true when source code is from `d.ts` file | ||
isAmbientContext: boolean | ||
} | ||
``` | ||
## Why? | ||
@@ -15,6 +36,10 @@ While main goal of this repository is to de the opposite (to help migrate from Flow to TypeScript), | ||
Why not [flowgen] - this should be similar to "flow to typescript", and so - keeping it simpler. | ||
Why not [flowgen]: | ||
However, [flowgen] does wonderful job converting the definitions files. Also, as confirmed while doing this - because TypeScript has more language features, converting it to Flow is harder. | ||
- this should be similar to "flow to typescript", and so - keeping it simpler. | ||
- because this plugin manipulates AST instead of generating the text directly - there is a bit more flexibility about what is possible. | ||
However, [flowgen] does wonderful job converting the definitions files. | ||
There are probably cases where it currently does better job comparing to this plugin. | ||
## Purpose | ||
@@ -24,10 +49,8 @@ | ||
However, it is not limited to only definition files, and many features already are supported. | ||
However, it is not limited to only definition files, and a lot of features already are supported. | ||
## Status | ||
Work in progress. Some features are missing. | ||
Still work in progress. Some features are missing. | ||
Currently, not actively working on it - instead, to focus on using [flowgen]. | ||
For the test cases that might be not covered - check `test` folder, there are some skipped test cases, to be implemented. | ||
@@ -34,0 +57,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
147254
158
1735
59
16
+ Addedbrowserslist@4.24.3(transitive)
+ Addedcaniuse-lite@1.0.30001690(transitive)
+ Addedelectron-to-chromium@1.5.76(transitive)
+ Addedupdate-browserslist-db@1.1.1(transitive)
- Removedbrowserslist@4.24.4(transitive)
- Removedcaniuse-lite@1.0.30001692(transitive)
- Removedelectron-to-chromium@1.5.79(transitive)
- Removedupdate-browserslist-db@1.1.2(transitive)
Updated@babel/traverse@^7.11.5
Updated@babel/types@^7.11.5