diff --git a/package.json b/package.json index a41b42aa..0bfc3291 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "devDependencies": { "@types/acorn": "4.0.5", - "@types/estree": "0.0.42", + "@types/estree": "0.0.44", "@types/node": "12.12.35", "@types/uuid": "7.0.2", "ava": "2.4.0", diff --git a/src/acorn.ts b/src/acorn.ts index fac481bc..16976c39 100644 --- a/src/acorn.ts +++ b/src/acorn.ts @@ -28,6 +28,7 @@ import { VariableDeclaration, ClassDeclaration, ExportSpecifier, + Property, } from 'estree'; import * as acorn from 'acorn'; import { log } from './debug'; @@ -96,3 +97,6 @@ export function isClassDeclaration(node: BaseNode): node is ClassDeclaration { export function isExportSpecifier(node: BaseNode): node is ExportSpecifier { return node.type === 'ExportSpecifier'; } +export function isProperty(node: BaseNode): node is Property { + return node.type === 'Property'; +} diff --git a/src/transformers/chunk/literal-computed-keys.ts b/src/transformers/chunk/literal-computed-keys.ts index d7be4871..d89a0122 100644 --- a/src/transformers/chunk/literal-computed-keys.ts +++ b/src/transformers/chunk/literal-computed-keys.ts @@ -18,7 +18,7 @@ import { ChunkTransform } from '../../transform'; import { Range, TransformInterface } from '../../types'; import MagicString from 'magic-string'; import { ObjectExpression } from 'estree'; -import { parse, walk } from '../../acorn'; +import { parse, walk, isProperty } from '../../acorn'; /** * Closure Compiler will not transform computed keys with literal values back to the literal value. @@ -40,7 +40,7 @@ export default class LiteralComputedKeys extends ChunkTransform implements Trans walk.simple(program, { ObjectExpression(node: ObjectExpression) { for (const property of node.properties) { - if (property.computed && property.key.type === 'Literal') { + if (isProperty(property) && property.computed && property.key.type === 'Literal') { const [propertyStart]: Range = property.range as Range; const [valueStart]: Range = property.value.range as Range; diff --git a/yarn.lock b/yarn.lock index 9ad34846..c0c0669a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -380,10 +380,10 @@ resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.40.tgz#0e6cb9b9bbd098031fa19e4b4e8131bc70e5de13" integrity sha512-p3KZgMto/JyxosKGmnLDJ/dG5wf+qTRMUjHJcspC2oQKa4jP7mz+tv0ND56lLBu3ojHlhzY33Ol+khLyNmilkA== -"@types/estree@0.0.42": - version "0.0.42" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.42.tgz#8d0c1f480339efedb3e46070e22dd63e0430dd11" - integrity sha512-K1DPVvnBCPxzD+G51/cxVIoc2X8uUVl1zpJeE6iKcgHMj4+tbat5Xu4TjV7v2QSDbIeAfLi2hIk+u2+s0MlpUQ== +"@types/estree@0.0.44": + version "0.0.44" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.44.tgz#980cc5a29a3ef3bea6ff1f7d021047d7ea575e21" + integrity sha512-iaIVzr+w2ZJ5HkidlZ3EJM8VTZb2MJLCjw3V+505yVts0gRC4UMvjw0d1HPtGqI/HQC/KdsYtayfzl+AXY2R8g== "@types/events@*": version "3.0.0"