PureKrome / EcmaScript.NET

C# Port of the Java EcmaScript project.
Other
15 stars 14 forks source link

"missing name after . operator" issue #4

Closed slgal closed 6 years ago

slgal commented 8 years ago

Hello, I am using YUI compressor and I found that it's throw an errors with one of my custom file. I did some debug and found that the problem inside EcmaScript.NET. Next code will throw an error:

An unhandled exception of type 'EcmaScript.NET.EcmaScriptRuntimeException' occurred in ConsoleApplication1.exe Additional information: missing name after . operator

static void Main(string[] args)
       {
            var js = @"alert(web.import);";
           using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(js)))
            {
                var stream = new StreamReader(memoryStream, Encoding.UTF8);
                 var compilerEnvirons = new CompilerEnvirons();
                var parser = new Parser(compilerEnvirons, new CustomErrorReporter());
                parser.Parse(stream, null, 1);
            }
        }

While var js = @"alert(web.import1);"; works fine.

Attach some other examples:

var js = @"signup.package = function () { }";
var js = @"resources.web.import.validation = function () { };";

EDIT: Fixed formatting by @PureKrome

slgal commented 8 years ago

Looks like import and package is js keywords. Is it possible to fix it?

PureKrome commented 8 years ago

hi @slgal - thanks for the issue.

I've had a quick play (read an hour or so) with the code and I could get import working (working == exception not thrown .. but not tested if it's still valid js, etc) but not package. I also had a quick look at the YUICompressor (original java version) and noticed that what i was playing around with ends up being a bit different to theirs.

also, their latest file(s) are waaaay newer than this repo's.

So these are my thoughts :

As such, I don't have the time to do this --- so I can't fix it. Happy to accept PR's but that's about it :(

I know that's not the answer you were hoping, so I'm sorry.

slgal commented 8 years ago

Hi @PureKrome, thank you for your answer. I downloaded the latest YUICompressor (v2.4.8) jar file and tried to compress file with same code. I get same results. See more here: https://github.com/yui/yuicompressor/issues/250

PureKrome commented 8 years ago

@slgal - great !! I've subscribed to that thread to see if anything might help. I've got a scary feeling that the entire code base (here) is waaay out of date so a huge effort will be needed to catch up to the latest java version.

mdvorscak commented 7 years ago

I have the same issue when attempting to compress:

var promise = new Promise(function (resolve, reject) {
    reject(new Error('Test'));
} );
promise
    .then(function(){console.log('success')})
    .catch(function(e) {console.error(e)});

I get the error: Message "missing name after . operator"

Full stack trace:

   at EcmaScript.NET.Parser.AddError(String messageId) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 96
   at EcmaScript.NET.Parser.ReportError(String messageId) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 103
   at EcmaScript.NET.Parser.memberExprTail(Boolean allowCallSyntax, Node pn) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1963
   at EcmaScript.NET.Parser.memberExpr(Boolean allowCallSyntax) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1898
   at EcmaScript.NET.Parser.unaryExpr() in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1736
   at EcmaScript.NET.Parser.mulExpr() in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1649
   at EcmaScript.NET.Parser.addExpr() in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1629
   at EcmaScript.NET.Parser.shiftExpr() in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1607
   at EcmaScript.NET.Parser.relExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1577
   at EcmaScript.NET.Parser.eqExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1525
   at EcmaScript.NET.Parser.bitAndExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1514
   at EcmaScript.NET.Parser.bitXorExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1503
   at EcmaScript.NET.Parser.bitOrExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1492
   at EcmaScript.NET.Parser.andExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1480
   at EcmaScript.NET.Parser.orExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1468
   at EcmaScript.NET.Parser.condExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1451
   at EcmaScript.NET.Parser.assignExpr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1433
   at EcmaScript.NET.Parser.expr(Boolean inForInit) in C:\projects\ecmascript-net\Code\EcmaScript.NET\Parser.cs:line 1422

Same issue as reported here: https://github.com/yui/yuicompressor/issues/203 (Note: the issue was fixed in the original yuicompressor project, see https://github.com/yui/yuicompressor/commit/840e5a00d249f6cdea186da725addf4171b8dc81)

PureKrome commented 7 years ago

Out of interest folks, what version of .NET framework are you guys using in your project, which is using this package?

mdvorscak commented 7 years ago

We're on 4.6.2

PureKrome commented 6 years ago

New pre-release is available on NuGet. please see if that fixes this issue.

More info in #8 about this.

alexazarh commented 6 years ago

I had the same problem like @mdvorscak and upgrading to the new pre-release solved it.

PureKrome commented 6 years ago

Oh nice! great to hear someone tested it :) Kewl. i'll give it a few more days before I make it an official release. Would love to hear if others can give it a go.