fix(compiler): make unary plus operator consistent to JavaScript (#22154)
fixes #22089 PR Close #22154
This commit is contained in:
parent
20a900b648
commit
72f8abd7b3
|
@ -477,7 +477,9 @@ export class _ParseAST {
|
|||
switch (operator) {
|
||||
case '+':
|
||||
this.advance();
|
||||
return this.parsePrefix();
|
||||
result = this.parsePrefix();
|
||||
return new Binary(
|
||||
this.span(start), '-', result, new LiteralPrimitive(new ParseSpan(start, start), 0));
|
||||
case '-':
|
||||
this.advance();
|
||||
result = this.parsePrefix();
|
||||
|
|
|
@ -103,7 +103,9 @@ import {validate} from './validator';
|
|||
|
||||
it('should parse unary - expressions', () => {
|
||||
checkAction('-1', '0 - 1');
|
||||
checkAction('+1', '1');
|
||||
checkAction('+1', '1 - 0');
|
||||
checkAction(`-'1'`, `0 - "1"`);
|
||||
checkAction(`+'1'`, `"1" - 0`);
|
||||
});
|
||||
|
||||
it('should parse unary ! expressions', () => {
|
||||
|
|
Loading…
Reference in New Issue