From 92c4c2dae996ffdd3c46fe5c151e40a708e257a3 Mon Sep 17 00:00:00 2001 From: Philipp Kreil Date: Thu, 20 Apr 2017 15:47:07 +0200 Subject: [PATCH 1/2] fixed "missing name after . operator" error for ES6 Promise .catch() calls use tokens as name if a name is expected but not supplied. I don't know if this has some bad side effects - for me it actually works quite well :D --- Code/EcmaScript.NET/Parser.cs | 9 ++++++++- Code/EcmaScript.NET/TokenStream.cs | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Code/EcmaScript.NET/Parser.cs b/Code/EcmaScript.NET/Parser.cs index ff25eaa..1c6db92 100644 --- a/Code/EcmaScript.NET/Parser.cs +++ b/Code/EcmaScript.NET/Parser.cs @@ -1961,7 +1961,14 @@ Node memberExprTail(bool allowCallSyntax, Node pn) default: - ReportError("msg.no.name.after.dot"); + s = ts.TokenString; + if (s.Length != 0) + { + decompiler.AddName(s); + pn = propertyName(pn, s, memberTypeFlags); + AddWarning("msg.reserved.keyword", s); + } else + ReportError("msg.no.name.after.dot"); break; } diff --git a/Code/EcmaScript.NET/TokenStream.cs b/Code/EcmaScript.NET/TokenStream.cs index a61694b..e469182 100644 --- a/Code/EcmaScript.NET/TokenStream.cs +++ b/Code/EcmaScript.NET/TokenStream.cs @@ -45,6 +45,14 @@ internal string String } } + + internal string TokenString + { + get + { + return tokenstr; + } + } internal double Number { get @@ -183,6 +191,8 @@ internal int Token ungetChar(c); string str = StringFromBuffer; + this.tokenstr = str; + if (!containsEscape) { // OPT we shouldn't have to make a string (object!) to @@ -1844,6 +1854,7 @@ private bool fillSourceBuffer() // string is found. Fosters one class of error, but saves lots of // code. private string str = ""; + private string tokenstr = ""; private double dNumber; From 61ed8204562be90bdaa2398350e0c9212a69fc22 Mon Sep 17 00:00:00 2001 From: Philipp Kreil Date: Thu, 20 Apr 2017 20:48:56 +0200 Subject: [PATCH 2/2] made previous fix more secure: ensure valid identifiers --- Code/EcmaScript.NET/Parser.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Code/EcmaScript.NET/Parser.cs b/Code/EcmaScript.NET/Parser.cs index 1c6db92..7f43fe0 100644 --- a/Code/EcmaScript.NET/Parser.cs +++ b/Code/EcmaScript.NET/Parser.cs @@ -13,6 +13,7 @@ using System; using System.Collections; +using System.Text.RegularExpressions; using EcmaScript.NET.Collections; @@ -41,6 +42,8 @@ public string EncodedSource internal const int TI_AFTER_EOL = 1 << 16; internal const int TI_CHECK_LABEL = 1 << 17; // indicates to check for label + internal readonly Regex SIMPLE_IDENTIFIER_NAME_PATTERN = new Regex("^[a-zA-Z_][a-zA-Z0-9_]*$", RegexOptions.Compiled); + internal CompilerEnvirons compilerEnv; ErrorReporter errorReporter; string sourceURI; @@ -1913,6 +1916,7 @@ Node memberExprTail(bool allowCallSyntax, Node pn) { int memberTypeFlags; string s; + Match match; consumeToken(); decompiler.AddToken(tt); @@ -1962,7 +1966,8 @@ Node memberExprTail(bool allowCallSyntax, Node pn) default: s = ts.TokenString; - if (s.Length != 0) + match = SIMPLE_IDENTIFIER_NAME_PATTERN.Match(s); + if (match.Success) { decompiler.AddName(s); pn = propertyName(pn, s, memberTypeFlags);