Skip to content

Commit

Permalink
refactor: remove object property shorthand syntax identifier
Browse files Browse the repository at this point in the history
- there's a bug for complex objects
  • Loading branch information
jorenrui committed Nov 21, 2023
1 parent 7ad56de commit d3a7e6b
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions lib/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,6 @@ export default class Lexer {
} else if (token.value === '}' && isObject) {
objectParent.pop();
if (objectParent.length === 0) isObject = false;

const lastToken = this._getLastToken();
const lastSecondToken = this._getLastToken(lastToken.index, [TOKEN.WhiteSpace, TOKEN.LineTerminatorSequence, TOKEN.Operator]);

// identify ES6 object property shorthand
if (lastToken?.type === TOKEN.IdentifierName && !(lastSecondToken?.type === TOKEN.Punctuator && lastSecondToken.value === ':')) {
if (this._tokens[this._tokens.length - 1]?.type === TOKEN.WhiteSpace)
this._tokens.pop();

this._tokens.push({ type: TOKEN.Punctuator, value: ':', index: this._tokens.length });
this._tokens.push({ type: TOKEN.WhiteSpace, value: ' ', index: this._tokens.length });
this._tokens.push({ type: lastToken.type, value: lastToken.value, index: this._tokens.length });
}
} else if (isObject && token.value === ',') {
const lastToken = this._getLastToken();
const lastSecondToken = this._getLastToken(lastToken.index, [TOKEN.WhiteSpace, TOKEN.LineTerminatorSequence, TOKEN.Operator]);

// identify ES6 object property shorthand
if (lastToken?.type === TOKEN.IdentifierName && !(lastSecondToken?.type === TOKEN.Punctuator && lastSecondToken.value === ':')) {
if (this._tokens[this._tokens.length - 1]?.type === TOKEN.WhiteSpace)
this._tokens.pop();

this._tokens.push({ type: TOKEN.Punctuator, value: ':', index: this._tokens.length });
this._tokens.push({ type: TOKEN.WhiteSpace, value: ' ', index: this._tokens.length });
this._tokens.push({ type: lastToken.type, value: lastToken.value, index: this._tokens.length });
}
} else if (token.value === '(') {
const variable = this._getLastToken();

Expand Down

0 comments on commit d3a7e6b

Please sign in to comment.