Skip to content

Commit

Permalink
Additional cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoferbaxter committed Jan 8, 2020
1 parent 6d706bb commit a586dee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/transformers/literal-computed-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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' ? ':' : ''}`,
);
}
});
}
},
});

Expand Down
8 changes: 5 additions & 3 deletions src/transformers/strict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
},
});
Expand Down

0 comments on commit a586dee

Please sign in to comment.