diff --git a/src/transformers/literal-computed-keys.ts b/src/transformers/literal-computed-keys.ts index 9284ecb5..d898018c 100644 --- a/src/transformers/literal-computed-keys.ts +++ b/src/transformers/literal-computed-keys.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Transform } from '../types'; +import { Transform, Range } from '../types'; import { TransformSourceDescription } from 'rollup'; import MagicString from 'magic-string'; import { ObjectExpression } from 'estree'; @@ -40,21 +40,18 @@ export default class LiteralComputedKeys extends Transform { walk.simple(program, { ObjectExpression(node: ObjectExpression) { - const properties = node.properties; - properties.forEach(property => { - if ( - property.computed && - property.key.type === 'Literal' && - property.range && - property.value.range - ) { + for (const property of node.properties) { + const [propertyStart]: Range = property.range as Range; + const [valueStart]: Range = property.value.range as Range; + + if (property.computed && property.key.type === 'Literal') { source.overwrite( - property.range[0], - property.value.range[0], + propertyStart, + valueStart, `${property.key.value}${property.value.type !== 'FunctionExpression' ? ':' : ''}`, ); } - }); + } }, }); diff --git a/src/transformers/strict.ts b/src/transformers/strict.ts index d0abb879..f4363f60 100644 --- a/src/transformers/strict.ts +++ b/src/transformers/strict.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Transform } from '../types'; +import { Transform, Range } from '../types'; import { isESMFormat } from '../options'; import { TransformSourceDescription } from 'rollup'; import MagicString from 'magic-string'; @@ -41,8 +41,10 @@ export default class StrictTransform extends Transform { walk.simple(program, { ExpressionStatement(node: ExpressionStatement) { const { type, value } = node.expression as SimpleLiteral; - if (type === 'Literal' && value === 'use strict' && node.range) { - source.remove(...node.range); + const range: Range = node.range as Range; + + if (type === 'Literal' && value === 'use strict') { + source.remove(...range); } }, });