Skip to content

Commit 6181ea6

Browse files
committed
fix sequence expressions
1 parent bd3c999 commit 6181ea6

File tree

2 files changed

+39
-30
lines changed

2 files changed

+39
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tsc-multi",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"description": "Compile multiple TypeScript projects into multiple targets.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/transformer.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,40 @@ export function createTransformer<T extends ts.SourceFile | ts.Bundle>(
228228
...ts.ExpressionStatement[]
229229
]
230230
> = Object.create(null);
231+
const shouldGroupExpression = (
232+
expression: ts.Expression
233+
): string | undefined => {
234+
if (options.ts.isBinaryExpression(expression)) {
235+
if (expression.operatorToken.kind === SyntaxKind.EqualsToken) {
236+
if (
237+
options.ts.isPropertyAccessExpression(expression.left) &&
238+
options.ts.isIdentifier(expression.left.expression) &&
239+
classes[expression.left.expression.text]
240+
) {
241+
return expression.left.expression.text;
242+
} else if (
243+
options.ts.isIdentifier(expression.left) &&
244+
options.ts.isIdentifier(expression.right) &&
245+
classes[expression.right.text] &&
246+
(expression.left as any)?.emitNode?.autoGenerate
247+
) {
248+
return expression.right.text;
249+
} else if (options.ts.isIdentifier(expression.left)) {
250+
// _BaseCloudflare_encoder = new WeakMap();
251+
const cls = (expression.left as any)?.emitNode?.autoGenerate
252+
?.prefix?.node?.text;
253+
if (classes[cls]) {
254+
return cls;
255+
}
256+
}
257+
} else if (expression.operatorToken.kind === SyntaxKind.CommaToken) {
258+
return (
259+
shouldGroupExpression(expression.right) ||
260+
shouldGroupExpression(expression.left)
261+
);
262+
}
263+
}
264+
};
231265
for (const statement of sourceFile.statements) {
232266
if (
233267
options.ts.isClassDeclaration(statement) &&
@@ -240,35 +274,10 @@ export function createTransformer<T extends ts.SourceFile | ts.Bundle>(
240274
])
241275
);
242276
continue;
243-
} else if (
244-
options.ts.isExpressionStatement(statement) &&
245-
options.ts.isBinaryExpression(statement.expression) &&
246-
statement.expression.operatorToken.kind === SyntaxKind.EqualsToken
247-
) {
248-
if (
249-
options.ts.isPropertyAccessExpression(statement.expression.left) &&
250-
options.ts.isIdentifier(statement.expression.left.expression) &&
251-
classes[statement.expression.left.expression.text]
252-
) {
253-
classes[statement.expression.left.expression.text].push(statement);
254-
continue;
255-
} else if (
256-
options.ts.isIdentifier(statement.expression.left) &&
257-
options.ts.isIdentifier(statement.expression.right) &&
258-
classes[statement.expression.right.text] &&
259-
(statement.expression.left as any)?.emitNode?.autoGenerate
260-
) {
261-
// _a = Cloudflare;
262-
// Cloudflare.Cloudflare = _a;
263-
classes[statement.expression.right.text].push(statement);
264-
continue;
265-
} else if (options.ts.isIdentifier(statement.expression.left)) {
266-
// _BaseCloudflare_encoder = new WeakMap();
267-
const cls = (statement.expression.left as any)?.emitNode
268-
?.autoGenerate?.prefix?.node?.text;
269-
if (classes[cls]) {
270-
classes[cls].push(statement);
271-
}
277+
} else if (options.ts.isExpressionStatement(statement)) {
278+
const cls = shouldGroupExpression(statement.expression);
279+
if (cls) {
280+
classes[cls].push(statement);
272281
continue;
273282
}
274283
}

0 commit comments

Comments
 (0)