@ts-liveserver/ts-transpiler
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -101,2 +101,7 @@ import CommonJsTransformer from '../../src/transformers/CommonJsTransformer' | ||
}) | ||
it('Should convert define.property with value', async () => { | ||
const input = | ||
'Object.defineProperty(exports, "__esModule", { value: true })' | ||
expect(await transformWithPlugin(input)).toMatchSnapshot() | ||
}) | ||
it('Should convert ObjectLiteralExpression', async () => { | ||
@@ -103,0 +108,0 @@ const input = 'module.exports = { a: b, c: d }' |
@@ -69,2 +69,12 @@ "use strict"; | ||
} | ||
const propertyValue = thirdArgument.properties | ||
.filter((property) => typescript_1.default.isPropertyAssignment(property)) | ||
.find((property) => typescript_1.default.isPropertyAssignment(property) && | ||
typescript_1.default.isIdentifier(property.name) && | ||
property.name.text === 'value'); | ||
if (propertyValue && | ||
typescript_1.default.isPropertyAssignment(propertyValue) && | ||
propertyValue.initializer) { | ||
return typescript_1.default.factory.createBinaryExpression(typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier(KEYNAME_EXPORTS), typescript_1.default.factory.createIdentifier(secondArgument.text)), typescript_1.default.SyntaxKind.EqualsToken, propertyValue.initializer); | ||
} | ||
} | ||
@@ -71,0 +81,0 @@ } |
{ | ||
"name": "@ts-liveserver/ts-transpiler", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -98,2 +98,24 @@ import TypeScript from 'typescript' | ||
} | ||
const propertyValue = thirdArgument.properties | ||
.filter((property) => TypeScript.isPropertyAssignment(property)) | ||
.find( | ||
(property) => | ||
TypeScript.isPropertyAssignment(property) && | ||
TypeScript.isIdentifier(property.name) && | ||
property.name.text === 'value', | ||
) | ||
if ( | ||
propertyValue && | ||
TypeScript.isPropertyAssignment(propertyValue) && | ||
propertyValue.initializer | ||
) { | ||
return TypeScript.factory.createBinaryExpression( | ||
TypeScript.factory.createPropertyAccessExpression( | ||
TypeScript.factory.createIdentifier(KEYNAME_EXPORTS), | ||
TypeScript.factory.createIdentifier(secondArgument.text), | ||
), | ||
TypeScript.SyntaxKind.EqualsToken, | ||
propertyValue.initializer, | ||
) | ||
} | ||
} | ||
@@ -100,0 +122,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
126961
2618