New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ts-liveserver/ts-transpiler

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-liveserver/ts-transpiler - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

8

__tests__/transformers/CommonJsTransformer.test.ts

@@ -22,2 +22,6 @@ import CommonJsTransformer from '../../src/transformers/CommonJsTransformer'

})
it('Should convert require without reference in sub-scope', async () => {
const input = 'if(true) { require("hello.js"); }'
expect(await transformWithPlugin(input)).toMatchSnapshot()
})
})

@@ -88,2 +92,6 @@ describe('Forwards', () => {

})
it('Should export one default', async () => {
const input = 'exports.default = "hello"'
expect(await transformWithPlugin(input)).toMatchSnapshot()
})
it('Should export nested expression', async () => {

@@ -90,0 +98,0 @@ const input = `

16

dist/transformers/CommonJsTransformer.js

@@ -292,7 +292,13 @@ "use strict";

inRootScope === false) {
const newIdentifierName = this.generateUniqueName();
newStatements.push(typescript_1.default.factory.createVariableStatement(undefined, typescript_1.default.factory.createVariableDeclarationList([
typescript_1.default.factory.createVariableDeclaration(newIdentifierName, undefined, undefined, node),
], typescript_1.default.NodeFlags.Let)));
return typescript_1.default.factory.createIdentifier(newIdentifierName);
if (node.parent && typescript_1.default.isExpressionStatement(node.parent)) {
newStatements.push(typescript_1.default.factory.createExpressionStatement(typescript_1.default.factory.createCallExpression(node.expression, undefined, node.arguments)));
return typescript_1.default.factory.createVoidExpression(typescript_1.default.factory.createNumericLiteral('0'));
}
else {
const newIdentifierName = this.generateUniqueName();
newStatements.push(typescript_1.default.factory.createVariableStatement(undefined, typescript_1.default.factory.createVariableDeclarationList([
typescript_1.default.factory.createVariableDeclaration(newIdentifierName, undefined, undefined, node),
], typescript_1.default.NodeFlags.Let)));
return typescript_1.default.factory.createIdentifier(newIdentifierName);
}
}

@@ -299,0 +305,0 @@ return typescript_1.default.visitEachChild(node, visit, this.context);

{
"name": "@ts-liveserver/ts-transpiler",
"version": "0.0.15",
"version": "0.0.16",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -459,4 +459,9 @@ import TypeScript from 'typescript'

): TypeScript.SourceFile {
const newStatements: TypeScript.VariableStatement[] = []
const visit = (node: TypeScript.Node): TypeScript.Node => {
const newStatements: (
| TypeScript.VariableStatement
| TypeScript.ExpressionStatement
)[] = []
const visit = (
node: TypeScript.Node,
): TypeScript.Node | TypeScript.Node[] | undefined => {
const inRootScope =

@@ -475,20 +480,35 @@ node?.parent?.parent?.parent?.parent &&

) {
const newIdentifierName = this.generateUniqueName()
newStatements.push(
TypeScript.factory.createVariableStatement(
undefined,
TypeScript.factory.createVariableDeclarationList(
[
TypeScript.factory.createVariableDeclaration(
newIdentifierName,
undefined,
undefined,
node,
),
],
TypeScript.NodeFlags.Let,
if (node.parent && TypeScript.isExpressionStatement(node.parent)) {
newStatements.push(
TypeScript.factory.createExpressionStatement(
TypeScript.factory.createCallExpression(
node.expression,
undefined,
node.arguments,
),
),
),
)
return TypeScript.factory.createIdentifier(newIdentifierName)
)
return TypeScript.factory.createVoidExpression(
TypeScript.factory.createNumericLiteral('0'),
)
} else {
const newIdentifierName = this.generateUniqueName()
newStatements.push(
TypeScript.factory.createVariableStatement(
undefined,
TypeScript.factory.createVariableDeclarationList(
[
TypeScript.factory.createVariableDeclaration(
newIdentifierName,
undefined,
undefined,
node,
),
],
TypeScript.NodeFlags.Let,
),
),
)
return TypeScript.factory.createIdentifier(newIdentifierName)
}
}

@@ -495,0 +515,0 @@ return TypeScript.visitEachChild(node, visit, this.context)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc