Ignore:
Timestamp:
Aug 27, 2014, 3:34:02 PM (11 years ago)
Author:
[email protected]
Message:

Deconstruction object pattern node emits the wrong start/end text positions
https://bugs.webkit.org/show_bug.cgi?id=136304

Patch by Saam Barati <[email protected]> on 2014-08-27
Reviewed by Geoffrey Garen.

Object pattern nodes that used the syntactic sugar binding:
'var {foo} = {foo:20}' instead of 'var {foo:foo} = {foo:20}'
would get the wrong text position for variable 'foo'. The position
would be placed on the comma(s)/closing brace instead of the identifier.
This patch fixes this bug by caching the identifier's JSToken before
trying to parse an optional colon.

  • parser/Parser.cpp:

(JSC::Parser<LexerType>::parseVarDeclarationList):
(JSC::Parser<LexerType>::createBindingPattern):
(JSC::Parser<LexerType>::parseDeconstructionPattern):

  • parser/Parser.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r172717 r173026  
    499499    } while (match(COMMA));
    500500    if (lastIdent)
    501         lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0);
     501        lastPattern = createBindingPattern(context, DeconstructToVariables, *lastIdent, 0, m_token);
    502502    return varDecls;
    503503}
    504504
    505505template <typename LexerType>
    506 template <class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DeconstructionKind kind, const Identifier& name, int depth)
     506template <class TreeBuilder> TreeDeconstructionPattern Parser<LexerType>::createBindingPattern(TreeBuilder& context, DeconstructionKind kind, const Identifier& name, int depth, JSToken token)
    507507{
    508508    ASSERT(!name.isEmpty());
     
    553553        }
    554554    }
    555     return context.createBindingLocation(m_token.m_location, name, m_token.m_startPosition, m_token.m_endPosition);
     555    return context.createBindingLocation(token.m_location, name, token.m_startPosition, token.m_endPosition);
    556556}
    557557
     
    611611            if (match(IDENT)) {
    612612                propertyName = *m_token.m_data.ident;
     613                JSToken identifierToken = m_token;
    613614                next();
    614615                if (consume(COLON))
    615616                    innerPattern = parseDeconstructionPattern(context, kind, depth + 1);
    616617                else
    617                     innerPattern = createBindingPattern(context, kind, propertyName, depth);
     618                    innerPattern = createBindingPattern(context, kind, propertyName, depth, identifierToken);
    618619            } else {
    619620                JSTokenType tokenType = m_token.m_type;
     
    666667            failWithMessage("Expected a parameter pattern or a ')' in parameter list");
    667668        }
    668         pattern = createBindingPattern(context, kind, *m_token.m_data.ident, depth);
     669        pattern = createBindingPattern(context, kind, *m_token.m_data.ident, depth, m_token);
    669670        next();
    670671        break;
Note: See TracChangeset for help on using the changeset viewer.