Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser don't allow leading 0 #487

Open
sinux-l5d opened this issue Feb 6, 2023 · 8 comments
Open

Parser don't allow leading 0 #487

sinux-l5d opened this issue Feb 6, 2023 · 8 comments

Comments

@sinux-l5d
Copy link

Hi,
I'm trying to parse a js file from a website, but the parser fails where my browser is fine.
The relevant js line is: "AddGenWeeks(22,08,2022,1,52,form.elements["weeks"]);"

package main

import (
	"github.com/robertkrimen/otto/parser"
)

func main() {
	_, err := parser.ParseFile(nil, "", "AddGenWeeks(22,8,2022,1,52,form.elements['weeks']);", 0) // works
	if err != nil {
		panic(err)
	}
	_, err = parser.ParseFile(nil, "", "AddGenWeeks(22,08,2022,1,52,form.elements['weeks']);", 0) // don't works
	if err != nil {
		panic(err)
	}
}

Is it expected result? Is there any workaround?

@Asday
Copy link

Asday commented Feb 6, 2023

https://262.ecma-international.org/5.1/#sec-7.8.3 leading zeroes are not permitted under es5. Your browser's javascript engine has been running es6 for a very long time, which otto does not support, as stated in the readme.

@sinux-l5d
Copy link
Author

Okey thanks, never actually coded for es5, so didn't know about this. I guess I'll have to find another way.

@Asday
Copy link

Asday commented Feb 7, 2023

Consider transpiling your ES6 to ES5 to run it under otto.

@stevenh
Copy link
Collaborator

stevenh commented Feb 7, 2023

@Asday is correct that's not a ES5 feature, but I'm happy to accept PR's which push us towards ES6.

@Asday
Copy link

Asday commented Feb 7, 2023

This is probably the incorrect location for this discussion, but I was wondering about that, @stevenh.

Do you suppose that ES6 support should be something separated from the ES5 support by some measure? Perhaps, on an es6 branch, until some measure of feature completeness is achieved?

If you were to accept PRs that implement little features here and there, especially if they're simple low-hanging fruit such as math functions and leading zeroes in numeric literals, I could imagine new users would start using otto, use some ES6 features, think that they all work, and then become frustrated when shiny-new-library.js doesn't work in hard to debug ways.

They already don't read that bit in the readme that says "ES5 only", so I don't think making it a more complex "ES5 only except this, this, this, this, and this" would help either.

@stevenh
Copy link
Collaborator

stevenh commented Feb 7, 2023

Before answering that are you aware of any backwards incompatible changes in ES6?

@Asday
Copy link

Asday commented Feb 8, 2023

Not one.

@stevenh
Copy link
Collaborator

stevenh commented Feb 8, 2023

In that case it sounds like we can make gradual progress towards ES6 without the need for a separate branch which would increase the overhead. We'll just need to create a way of tracking, so it's clear what has been done.

Obviously encouraging people to contribute enhancements / bug fixes to address issues as they occur will be key to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants