Improve handling of JS
This commit is contained in:
parent
407acf01a6
commit
204bd950a4
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"js punctuators": {
|
"js punctuators": {
|
||||||
"value_type": "bool",
|
"value_type": "bool",
|
||||||
|
"//": "Some values are missing here because they are manually handled in `process_js_script` function.",
|
||||||
"values": {
|
"values": {
|
||||||
"!": "true",
|
"!": "true",
|
||||||
"!=": "true",
|
"!=": "true",
|
||||||
|
@ -10,8 +11,6 @@
|
||||||
"&": "true",
|
"&": "true",
|
||||||
"&&": "true",
|
"&&": "true",
|
||||||
"&=": "true",
|
"&=": "true",
|
||||||
"(": "true",
|
|
||||||
")": "true",
|
|
||||||
"*": "true",
|
"*": "true",
|
||||||
"**": "true",
|
"**": "true",
|
||||||
"**=": "true",
|
"**=": "true",
|
||||||
|
@ -23,10 +22,7 @@
|
||||||
"-": "true",
|
"-": "true",
|
||||||
"--": "true",
|
"--": "true",
|
||||||
"-=": "true",
|
"-=": "true",
|
||||||
".": "true",
|
|
||||||
"...": "true",
|
"...": "true",
|
||||||
"/": "true",
|
|
||||||
"/=": "true",
|
|
||||||
":": "true",
|
":": "true",
|
||||||
";": "true",
|
";": "true",
|
||||||
"<": "true",
|
"<": "true",
|
||||||
|
@ -45,7 +41,6 @@
|
||||||
">>>=": "true",
|
">>>=": "true",
|
||||||
"?": "true",
|
"?": "true",
|
||||||
"[": "true",
|
"[": "true",
|
||||||
"]": "true",
|
|
||||||
"^": "true",
|
"^": "true",
|
||||||
"^=": "true",
|
"^=": "true",
|
||||||
"{": "true",
|
"{": "true",
|
||||||
|
|
|
@ -66,6 +66,7 @@ enum Syntax {
|
||||||
Punctuator,
|
Punctuator,
|
||||||
IfWhileForWithParentheses,
|
IfWhileForWithParentheses,
|
||||||
GroupingParentheses,
|
GroupingParentheses,
|
||||||
|
ArrayLiteralOrComputedProperty,
|
||||||
LiteralStringOrTemplate,
|
LiteralStringOrTemplate,
|
||||||
LiteralNumber,
|
LiteralNumber,
|
||||||
LiteralRegExp,
|
LiteralRegExp,
|
||||||
|
@ -278,6 +279,7 @@ pub fn process_js_script(proc: &mut Processor) -> ProcessingResult<()> {
|
||||||
discarded_whitespace = true;
|
discarded_whitespace = true;
|
||||||
}
|
}
|
||||||
b'.' => {
|
b'.' => {
|
||||||
|
// TODO Handle `...`
|
||||||
if is_digit(proc.peek_offset(1)?) {
|
if is_digit(proc.peek_offset(1)?) {
|
||||||
// Is numeric literal starting with decimal dot.
|
// Is numeric literal starting with decimal dot.
|
||||||
parse_literal_number(proc)?;
|
parse_literal_number(proc)?;
|
||||||
|
@ -308,6 +310,10 @@ pub fn process_js_script(proc: &mut Processor) -> ProcessingResult<()> {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
b']' => {
|
||||||
|
proc.accept_expect();
|
||||||
|
last_syntax = Syntax::ArrayLiteralOrComputedProperty;
|
||||||
|
}
|
||||||
c if is_digit(c) => {
|
c if is_digit(c) => {
|
||||||
parse_literal_number(proc)?;
|
parse_literal_number(proc)?;
|
||||||
last_syntax = Syntax::LiteralNumber;
|
last_syntax = Syntax::LiteralNumber;
|
||||||
|
@ -315,6 +321,11 @@ pub fn process_js_script(proc: &mut Processor) -> ProcessingResult<()> {
|
||||||
b'/' => match proc.peek_offset(1)? {
|
b'/' => match proc.peek_offset(1)? {
|
||||||
b'/' => parse_comment_single(proc)?,
|
b'/' => parse_comment_single(proc)?,
|
||||||
b'*' => parse_comment_multi(proc)?,
|
b'*' => parse_comment_multi(proc)?,
|
||||||
|
b'=' => {
|
||||||
|
// Is `/=` operator.
|
||||||
|
proc.accept_amount_expect(2);
|
||||||
|
last_syntax = Syntax::Punctuator;
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let is_regex = match last_syntax {
|
let is_regex = match last_syntax {
|
||||||
Syntax::IfWhileForWithParentheses => true,
|
Syntax::IfWhileForWithParentheses => true,
|
||||||
|
|
Loading…
Reference in New Issue