Commit 72432f96 by kzc Committed by Marijn Haverbeke

use code.slice() in computed property destructuring

parent c3fe3a1a
Pipeline #5379857 passed with stage
in 2 minutes 56 seconds
......@@ -120,7 +120,7 @@ export default class AssignmentExpression extends Node {
const props = pattern.properties;
if ( props.length == 1 ) {
const prop = props[0];
const value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.original.substring(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
const value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.slice(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
destructure( prop.value, value, false );
}
else {
......@@ -131,7 +131,7 @@ export default class AssignmentExpression extends Node {
ref = temp;
}
props.forEach( prop => {
const value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.original.substring(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
const value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.slice(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
destructure( prop.value, value, false );
} );
}
......
......@@ -57,7 +57,7 @@ function destructureObjectPattern ( code, scope, node, ref, inline, statementGen
let c = node.start;
node.properties.forEach( prop => {
let value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.original.substring(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
let value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.slice(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
handleProperty( code, scope, c, prop.value, value, inline, statementGenerators );
c = prop.end;
});
......@@ -126,13 +126,13 @@ function handleProperty ( code, scope, c, node, value, inline, statementGenerato
});
node.properties.forEach( prop => {
const value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.original.substring(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
const value = prop.computed || prop.key.type !== 'Identifier' ? `${ref}[${code.slice(prop.key.start, prop.key.end)}]` : `${ref}.${prop.key.name}`;
handleProperty( code, scope, c, prop.value, value, inline, statementGenerators );
c = prop.end;
});
} else {
const prop = node.properties[0];
const value_suffix = prop.computed || prop.key.type !== 'Identifier' ? `[${code.original.substring(prop.key.start, prop.key.end)}]` : `.${prop.key.name}`;
const value_suffix = prop.computed || prop.key.type !== 'Identifier' ? `[${code.slice(prop.key.start, prop.key.end)}]` : `.${prop.key.name}`;
handleProperty( code, scope, c, prop.value, `${value}${value_suffix}`, inline, statementGenerators );
c = prop.end;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment