Skip to content

Commit ca7062d

Browse files
Alexey AndreevAlexey Andreev
Alexey Andreev
authored and
Alexey Andreev
committed
Fix JS parser to properly handle "." <keyword> sequence
1 parent 9e89213 commit ca7062d

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

js/js.parser/src/com/google/gwt/dev/js/rhino/Parser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,9 @@ private Object memberExprTail(TokenStream ts, boolean allowCallSyntax,
995995
int tt;
996996
while ((tt = ts.getToken()) > ts.EOF) {
997997
if (tt == ts.DOT) {
998+
ts.treatKeywordAsIdentifier = true;
998999
mustMatchToken(ts, ts.NAME, "msg.no.name.after.dot");
999-
String s = ts.getString();
1000+
ts.treatKeywordAsIdentifier = false;
10001001
pn = nf.createBinary(ts.DOT, pn, nf.createName(ts.getString()));
10011002
/*
10021003
* pn = nf.createBinary(ts.DOT, pn, memberExpr(ts)) is the version in

js/js.parser/src/com/google/gwt/dev/js/rhino/TokenStream.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ private int getTokenHelper() throws IOException {
695695
in.unread();
696696

697697
String str = getStringFromBuffer();
698-
if (!containsEscape) {
698+
if (!containsEscape && !treatKeywordAsIdentifier) {
699699
// OPT we shouldn't have to make a string (object!) to
700700
// check if it's a keyword.
701701

@@ -1477,6 +1477,7 @@ private void updatePosition() {
14771477
CodePosition lastPosition;
14781478

14791479
private int op;
1480+
public boolean treatKeywordAsIdentifier;
14801481

14811482
// Set this to an inital non-null value so that the Parser has
14821483
// something to retrieve even if an error has occured and no

js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4664,6 +4664,12 @@ public void testExternalInlineNewDecomposed() throws Exception {
46644664
doTest(fileName);
46654665
}
46664666

4667+
@TestMetadata("keywordAsMemberName.kt")
4668+
public void testKeywordAsMemberName() throws Exception {
4669+
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inlineMultiModule/keywordAsMemberName.kt");
4670+
doTest(fileName);
4671+
}
4672+
46674673
@TestMetadata("kt16144.kt")
46684674
public void testKt16144() throws Exception {
46694675
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/inlineMultiModule/kt16144.kt");
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// MINIFICATION_THRESHOLD: 481
2+
// MODULE: lib
3+
// FILE: lib.kt
4+
class A {
5+
fun instanceof() = "OK"
6+
}
7+
8+
inline fun foo() = A().instanceof()
9+
10+
// MODULE: main(lib)
11+
// FILE: main.kt
12+
13+
fun box() = foo()

0 commit comments

Comments
 (0)