From ed8b7eb54cc0077fb5003973cfc8ed2b7d05a050 Mon Sep 17 00:00:00 2001 From: wessberg Date: Fri, 23 Oct 2020 10:23:43 +0200 Subject: [PATCH] fix(build): add workaround in visitor for swc --- src/build/swc/unicode-escape-restorer.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/build/swc/unicode-escape-restorer.ts b/src/build/swc/unicode-escape-restorer.ts index 99955e1..e1743b9 100644 --- a/src/build/swc/unicode-escape-restorer.ts +++ b/src/build/swc/unicode-escape-restorer.ts @@ -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,