Changeset 288473 in webkit for trunk/Source/JavaScriptCore/parser/Parser.cpp
- Timestamp:
- Jan 24, 2022, 2:51:13 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/Parser.cpp
r284435 r288473 3577 3577 3578 3578 template <typename LexerType> 3579 template <class TreeBuilder> typename TreeBuilder::ImportAssertionList Parser<LexerType>::parseImportAssertions(TreeBuilder& context) 3580 { 3581 auto assertionList = context.createImportAssertionList(); 3582 consumeOrFail(OPENBRACE, "Expected opening '{' at the start of import assertion"); 3583 while (!match(CLOSEBRACE)) { 3584 failIfFalse(matchIdentifierOrKeyword() || match(STRING), "Expected an assertion key"); 3585 auto key = m_token.m_data.ident; 3586 next(); 3587 consumeOrFail(COLON, "Expected ':' after assertion key"); 3588 failIfFalse(match(STRING), "Expected an assertion value"); 3589 auto value = m_token.m_data.ident; 3590 next(); 3591 context.appendImportAssertion(assertionList, *key, *value); 3592 if (!consume(COMMA)) 3593 break; 3594 } 3595 handleProductionOrFail2(CLOSEBRACE, "}", "end", "import assertion"); 3596 return assertionList; 3597 } 3598 3599 template <typename LexerType> 3579 3600 template <class TreeBuilder> TreeStatement Parser<LexerType>::parseImportDeclaration(TreeBuilder& context) 3580 3601 { … … 3588 3609 if (match(STRING)) { 3589 3610 // import ModuleSpecifier ; 3611 // import ModuleSpecifier [no LineTerminator here] AssertClause ; 3590 3612 auto moduleName = parseModuleName(context); 3591 3613 failIfFalse(moduleName, "Cannot parse the module name"); 3614 3615 typename TreeBuilder::ImportAssertionList assertionList = 0; 3616 if (Options::useImportAssertion() && !m_lexer->hasLineTerminatorBeforeToken() && matchContextualKeyword(m_vm.propertyNames->builtinNames().assertPublicName())) { 3617 next(); 3618 assertionList = parseImportAssertions(context); 3619 failIfFalse(assertionList, "Unable to parse import assertion"); 3620 } 3621 3592 3622 failIfFalse(autoSemiColon(), "Expected a ';' following a targeted import declaration"); 3593 return context.createImportDeclaration(importLocation, specifierList, moduleName );3623 return context.createImportDeclaration(importLocation, specifierList, moduleName, assertionList); 3594 3624 } 3595 3625 … … 3641 3671 auto moduleName = parseModuleName(context); 3642 3672 failIfFalse(moduleName, "Cannot parse the module name"); 3673 3674 // [no LineTerminator here] AssertClause ; 3675 typename TreeBuilder::ImportAssertionList assertionList = 0; 3676 if (Options::useImportAssertion() && !m_lexer->hasLineTerminatorBeforeToken() && matchContextualKeyword(m_vm.propertyNames->builtinNames().assertPublicName())) { 3677 next(); 3678 assertionList = parseImportAssertions(context); 3679 failIfFalse(assertionList, "Unable to parse import assertion"); 3680 } 3681 3643 3682 failIfFalse(autoSemiColon(), "Expected a ';' following a targeted import declaration"); 3644 3683 3645 return context.createImportDeclaration(importLocation, specifierList, moduleName );3684 return context.createImportDeclaration(importLocation, specifierList, moduleName, assertionList); 3646 3685 } 3647 3686 … … 3715 3754 auto moduleName = parseModuleName(context); 3716 3755 failIfFalse(moduleName, "Cannot parse the 'from' clause"); 3756 3757 // [no LineTerminator here] AssertClause ; 3758 typename TreeBuilder::ImportAssertionList assertionList = 0; 3759 if (Options::useImportAssertion() && !m_lexer->hasLineTerminatorBeforeToken() && matchContextualKeyword(m_vm.propertyNames->builtinNames().assertPublicName())) { 3760 next(); 3761 assertionList = parseImportAssertions(context); 3762 failIfFalse(assertionList, "Unable to parse import assertion"); 3763 } 3764 3717 3765 failIfFalse(autoSemiColon(), "Expected a ';' following a targeted export declaration"); 3718 3766 … … 3723 3771 auto specifier = context.createExportSpecifier(specifierLocation, *localName, *exportedName); 3724 3772 context.appendExportSpecifier(specifierList, specifier); 3725 return context.createExportNamedDeclaration(exportLocation, specifierList, moduleName );3726 } 3727 3728 return context.createExportAllDeclaration(exportLocation, moduleName );3773 return context.createExportNamedDeclaration(exportLocation, specifierList, moduleName, assertionList); 3774 } 3775 3776 return context.createExportAllDeclaration(exportLocation, moduleName, assertionList); 3729 3777 } 3730 3778 … … 3848 3896 3849 3897 typename TreeBuilder::ModuleName moduleName = 0; 3898 typename TreeBuilder::ImportAssertionList assertionList = 0; 3850 3899 if (matchContextualKeyword(m_vm.propertyNames->from)) { 3851 3900 next(); 3852 3901 moduleName = parseModuleName(context); 3853 3902 failIfFalse(moduleName, "Cannot parse the 'from' clause"); 3903 3904 // [no LineTerminator here] AssertClause ; 3905 if (Options::useImportAssertion() && !m_lexer->hasLineTerminatorBeforeToken() && matchContextualKeyword(m_vm.propertyNames->builtinNames().assertPublicName())) { 3906 next(); 3907 assertionList = parseImportAssertions(context); 3908 failIfFalse(assertionList, "Unable to parse import assertion"); 3909 } 3854 3910 } else 3855 3911 semanticFailIfTrue(hasReferencedModuleExportNames, "Cannot use module export names if they reference variable names in the current module"); … … 3873 3929 } 3874 3930 3875 return context.createExportNamedDeclaration(exportLocation, specifierList, moduleName );3931 return context.createExportNamedDeclaration(exportLocation, specifierList, moduleName, assertionList); 3876 3932 } 3877 3933 … … 5137 5193 } else { 5138 5194 semanticFailIfTrue(newCount, "Cannot use new with import"); 5139 consumeOrFail(OPENPAREN, "import call expects exactly one argument");5195 consumeOrFail(OPENPAREN, "import call expects one or two arguments"); 5140 5196 TreeExpression expr = parseAssignmentExpression(context); 5141 5197 failIfFalse(expr, "Cannot parse expression"); 5142 consumeOrFail(CLOSEPAREN, "import call expects exactly one argument"); 5143 base = context.createImportExpr(location, expr, expressionStart, expressionEnd, lastTokenEndPosition()); 5198 TreeExpression optionExpression = 0; 5199 if (consume(COMMA)) { 5200 if (!match(CLOSEPAREN)) { 5201 optionExpression = parseAssignmentExpression(context); 5202 failIfFalse(optionExpression, "Cannot parse expression"); 5203 consume(COMMA); 5204 } 5205 } 5206 consumeOrFail(CLOSEPAREN, "import call expects one or two arguments"); 5207 base = context.createImportExpr(location, expr, optionExpression, expressionStart, expressionEnd, lastTokenEndPosition()); 5144 5208 } 5145 5209 } else if (!baseIsNewTarget) {
Note:
See TracChangeset
for help on using the changeset viewer.