Skip to content

Commit

Permalink
Update types and fix issue related to isProperty check missing for Ob…
Browse files Browse the repository at this point in the history
…jectExpression members
  • Loading branch information
kristoferbaxter committed Apr 13, 2020
1 parent f05347c commit 32008cc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/acorn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
VariableDeclaration,
ClassDeclaration,
ExportSpecifier,
Property,
} from 'estree';
import * as acorn from 'acorn';
import { log } from './debug';
Expand Down Expand Up @@ -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';
}
4 changes: 2 additions & 2 deletions src/transformers/chunk/literal-computed-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 32008cc

Please sign in to comment.