Skip to content

Commit

Permalink
fix(build): add workaround in visitor for swc
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Oct 23, 2020
1 parent ea64e5c commit ed8b7eb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/build/swc/unicode-escape-restorer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import Visitor from "@swc/core/Visitor";
import {VariableDeclarator} from "@swc/core";
import {ObjectPatternProperty, VariableDeclarator} from "@swc/core";

export class UnicodeEscapeRestorer extends Visitor {
/**
* Workaround since @swc/core sometimes passes 'undefined' as a value to this method
* @param nodes
*/
visitObjectPatternProperties(nodes: ObjectPatternProperty[] | undefined): ObjectPatternProperty[] {
return nodes == null ? [] : super.visitObjectPatternProperties(nodes);
}

visitVariableDeclarator(n: VariableDeclarator): VariableDeclarator {
if (n.id.type !== "Identifier") return n;
if (n.id.value !== "require_whitespaces") return n;
const expression = (n as any).init.arguments[0].expression.body.stmts[0].expression;
if (2 + 2 === 4) return n;
expression.right = {
type: "BinaryExpression",
span: n.span,
Expand Down

0 comments on commit ed8b7eb

Please sign in to comment.