@aurelia/expression-parser
Advanced tools
Comparing version 2.0.0-beta.20 to 2.0.0-beta.21
@@ -6,2 +6,9 @@ # Change Log | ||
<a name="2.0.0-beta.21"></a> | ||
# 2.0.0-beta.21 (2024-08-08) | ||
### Features: | ||
* **ast:** Increment/decrement assign (#2004) ([4cfc0a3](https://github.com/aurelia/aurelia/commit/4cfc0a3)) | ||
<a name="2.0.0-beta.20"></a> | ||
@@ -8,0 +15,0 @@ # 2.0.0-beta.20 (2024-07-07) |
import type { IVisitor } from './ast.visitor'; | ||
export type ExpressionKind = 'AccessThis' | 'AccessGlobal' | 'AccessBoundary' | 'AccessScope' | 'ArrayLiteral' | 'ObjectLiteral' | 'PrimitiveLiteral' | 'Template' | 'Unary' | 'CallScope' | 'CallMember' | 'CallFunction' | 'CallGlobal' | 'AccessMember' | 'AccessKeyed' | 'TaggedTemplate' | 'Binary' | 'Conditional' | 'Assign' | 'ArrowFunction' | 'ValueConverter' | 'BindingBehavior' | 'ArrayBindingPattern' | 'ObjectBindingPattern' | 'BindingIdentifier' | 'ForOfStatement' | 'Interpolation' | 'ArrayDestructuring' | 'ObjectDestructuring' | 'DestructuringAssignmentLeaf' | 'Custom'; | ||
export type UnaryOperator = 'void' | 'typeof' | '!' | '-' | '+'; | ||
export type UnaryOperator = 'void' | 'typeof' | '!' | '-' | '+' | '++' | '--'; | ||
export type BinaryOperator = '??' | '&&' | '||' | '==' | '===' | '!=' | '!==' | 'instanceof' | 'in' | '+' | '-' | '*' | '/' | '%' | '<' | '>' | '<=' | '>='; | ||
export type AssignmentOperator = '=' | '/=' | '*=' | '+=' | '-='; | ||
export type IsPrimary = AccessThisExpression | AccessBoundaryExpression | AccessScopeExpression | AccessGlobalExpression | ArrayLiteralExpression | ObjectLiteralExpression | PrimitiveLiteralExpression | TemplateExpression; | ||
@@ -50,4 +51,5 @@ export type IsLiteral = ArrayLiteralExpression | ObjectLiteralExpression | PrimitiveLiteralExpression | TemplateExpression; | ||
readonly value: IsAssign; | ||
readonly op: AssignmentOperator; | ||
readonly $kind = "Assign"; | ||
constructor(target: IsAssignable, value: IsAssign); | ||
constructor(target: IsAssignable, value: IsAssign, op?: AssignmentOperator); | ||
} | ||
@@ -136,4 +138,5 @@ export declare class ConditionalExpression { | ||
readonly expression: IsLeftHandSide; | ||
readonly pos: 0 | 1; | ||
readonly $kind = "Unary"; | ||
constructor(operation: UnaryOperator, expression: IsLeftHandSide); | ||
constructor(operation: UnaryOperator, expression: IsLeftHandSide, pos?: 0 | 1); | ||
} | ||
@@ -140,0 +143,0 @@ export declare class PrimitiveLiteralExpression<TValue extends null | undefined | number | boolean | string = null | undefined | number | boolean | string> { |
@@ -22,2 +22,3 @@ import { CustomExpression, ForOfStatement, Interpolation, AnyBindingExpression, IsBindingBehavior } from './ast'; | ||
Conditional = 63, | ||
Assignment = 64, | ||
NullishCoalescing = 128, | ||
@@ -24,0 +25,0 @@ LogicalOR = 192, |
@@ -1,4 +0,4 @@ | ||
export { type ExpressionKind, CallFunctionExpression, CallGlobalExpression, CustomExpression, BindingBehaviorExpression, ValueConverterExpression, AssignExpression, ConditionalExpression, AccessThisExpression, AccessGlobalExpression, AccessScopeExpression, AccessBoundaryExpression, AccessMemberExpression, AccessKeyedExpression, CallScopeExpression, CallMemberExpression, BinaryExpression, UnaryExpression, PrimitiveLiteralExpression, ArrayLiteralExpression, ObjectLiteralExpression, TemplateExpression, TaggedTemplateExpression, ArrayBindingPattern, ObjectBindingPattern, BindingIdentifier, ForOfStatement, Interpolation, DestructuringAssignmentExpression, DestructuringAssignmentSingleExpression, DestructuringAssignmentRestExpression, ArrowFunction, type AnyBindingExpression, type IsPrimary, type IsLiteral, type IsLeftHandSide, type IsUnary, type IsBinary, type IsConditional, type IsAssign, type IsValueConverter, type IsBindingBehavior, type IsAssignable, type IsExpression, type IsExpressionOrStatement, type BinaryOperator, type BindingIdentifierOrPattern, type UnaryOperator, } from './ast'; | ||
export { type ExpressionKind, CallFunctionExpression, CallGlobalExpression, CustomExpression, BindingBehaviorExpression, ValueConverterExpression, AssignExpression, ConditionalExpression, AccessThisExpression, AccessGlobalExpression, AccessScopeExpression, AccessBoundaryExpression, AccessMemberExpression, AccessKeyedExpression, CallScopeExpression, CallMemberExpression, BinaryExpression, UnaryExpression, PrimitiveLiteralExpression, ArrayLiteralExpression, ObjectLiteralExpression, TemplateExpression, TaggedTemplateExpression, ArrayBindingPattern, ObjectBindingPattern, BindingIdentifier, ForOfStatement, Interpolation, DestructuringAssignmentExpression, DestructuringAssignmentSingleExpression, DestructuringAssignmentRestExpression, ArrowFunction, type AnyBindingExpression, type IsPrimary, type IsLiteral, type IsLeftHandSide, type IsUnary, type IsBinary, type IsConditional, type IsAssign, type IsValueConverter, type IsBindingBehavior, type IsAssignable, type IsExpression, type IsExpressionOrStatement, type BinaryOperator, type AssignmentOperator, type BindingIdentifierOrPattern, type UnaryOperator, } from './ast'; | ||
export { astVisit, type IVisitor, Unparser } from './ast.visitor'; | ||
export { IExpressionParser, ExpressionParser, ExpressionType, parseExpression, } from './expression-parser'; | ||
export { IExpressionParser, ExpressionParser, type ExpressionType, parseExpression, } from './expression-parser'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@aurelia/expression-parser", | ||
"version": "2.0.0-beta.20", | ||
"version": "2.0.0-beta.21", | ||
"main": "dist/cjs/index.cjs", | ||
@@ -56,3 +56,3 @@ "module": "dist/esm/index.mjs", | ||
"dependencies": { | ||
"@aurelia/kernel": "2.0.0-beta.20" | ||
"@aurelia/kernel": "2.0.0-beta.21" | ||
}, | ||
@@ -59,0 +59,0 @@ "devDependencies": { |
@@ -70,6 +70,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ | ||
export type UnaryOperator = 'void' | 'typeof' | '!' | '-' | '+'; | ||
export type UnaryOperator = 'void' | 'typeof' | '!' | '-' | '+' | '++' | '--'; | ||
export type BinaryOperator = '??' | '&&' | '||' | '==' | '===' | '!=' | '!==' | 'instanceof' | 'in' | '+' | '-' | '*' | '/' | '%' | '<' | '>' | '<=' | '>='; | ||
export type AssignmentOperator = '=' | '/=' | '*=' | '+=' | '-='; | ||
export type IsPrimary = AccessThisExpression | AccessBoundaryExpression | AccessScopeExpression | AccessGlobalExpression | ArrayLiteralExpression | ObjectLiteralExpression | PrimitiveLiteralExpression | TemplateExpression; | ||
@@ -149,2 +149,3 @@ export type IsLiteral = ArrayLiteralExpression | ObjectLiteralExpression | PrimitiveLiteralExpression | TemplateExpression; | ||
public readonly value: IsAssign, | ||
public readonly op: AssignmentOperator = '=', | ||
) {} | ||
@@ -274,2 +275,3 @@ } | ||
public readonly expression: IsLeftHandSide, | ||
public readonly pos: 0 | 1 = 0, | ||
) {} | ||
@@ -276,0 +278,0 @@ } |
@@ -54,2 +54,3 @@ /* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */ | ||
AccessBoundaryExpression, | ||
AssignmentOperator, | ||
} from './ast'; | ||
@@ -264,2 +265,3 @@ import { createLookup } from './utilities'; | ||
Conditional = 0b0000_111111, | ||
Assignment = 0b0001_000000, | ||
NullishCoalescing = 0b0010_000000, | ||
@@ -349,2 +351,8 @@ LogicalOR = 0b0011_000000, | ||
Arrow = 0b0000000000000_0000_110011, | ||
PlusEquals = 0b1000000000000_0000_110100, | ||
MinusEquals = 0b1000000000000_0000_110101, | ||
AsteriskEquals = 0b1000000000000_0000_110110, | ||
SlashEquals = 0b1000000000000_0000_110111, | ||
PlusPlus = 0b0100010000000_0000_111000, | ||
MinusMinus = 0b0100010000000_0000_111001, | ||
} | ||
@@ -451,8 +459,10 @@ _END_CONST_ENUM(); | ||
* 6. ! UnaryExpression | ||
* 7. ++ UnaryExpression | ||
* 8. -- UnaryExpression | ||
* | ||
* IsValidAssignmentTarget | ||
* 2,3,4,5,6 = false | ||
* 2,3,4,5,6,7,8 = false | ||
* 1 = see parseLeftHandSideExpression | ||
* | ||
* Note: technically we should throw on ++ / -- / +++ / ---, but there's nothing to gain from that | ||
* Note: technically we should throw on +++ / ---, but there's nothing to gain from that | ||
*/ | ||
@@ -621,2 +631,10 @@ const op = TokenValues[$currentToken & Token.Type] as UnaryOperator; | ||
} | ||
switch ($currentToken as Token) { | ||
case Token.PlusPlus: | ||
case Token.MinusMinus: | ||
result = new UnaryExpression(TokenValues[$currentToken & Token.Type] as UnaryOperator, result as IsLeftHandSide, 1); | ||
nextToken(); | ||
$assignable = false; | ||
break; | ||
} | ||
if (Precedence.LeftHandSide < minPrecedence) { | ||
@@ -841,2 +859,3 @@ return result as any; | ||
* 2. LeftHandSideExpression = AssignmentExpression | ||
* 3. LeftHandSideExpression AssignmentOperator AssignmentExpression | ||
* | ||
@@ -846,7 +865,17 @@ * IsValidAssignmentTarget | ||
*/ | ||
if (consumeOpt(Token.Equals)) { | ||
if (!$assignable) { | ||
throw lhsNotAssignable(); | ||
switch ($currentToken as Token) { | ||
case Token.Equals: | ||
case Token.PlusEquals: | ||
case Token.MinusEquals: | ||
case Token.AsteriskEquals: | ||
case Token.SlashEquals: { | ||
if (!$assignable) { | ||
throw lhsNotAssignable(); | ||
} | ||
const op = TokenValues[$currentToken & Token.Type] as AssignmentOperator; | ||
nextToken(); | ||
result = new AssignExpression(result as IsAssignable, parse(Precedence.Assign, expressionType) as IsAssign, op); | ||
break; | ||
} | ||
result = new AssignExpression(result as IsAssignable, parse(Precedence.Assign, expressionType) as IsAssign); | ||
} | ||
@@ -1082,3 +1111,2 @@ if (Precedence.Variadic < minPrecedence) { | ||
const tokenValueSave = $tokenValue; | ||
const assignableSave = $assignable; | ||
const optionalSave = $optional; | ||
@@ -1232,3 +1260,2 @@ | ||
$tokenValue = tokenValueSave; | ||
$assignable = assignableSave; | ||
$optional = optionalSave; | ||
@@ -1719,3 +1746,3 @@ | ||
Token.TemplateTail, Token.TemplateContinuation, | ||
'of', '=>' | ||
'of', '=>', '+=', '-=', '*=', '/=', '++', '--' | ||
]; | ||
@@ -1924,7 +1951,49 @@ | ||
CharScanners[Char.CloseParen] = returnToken(Token.CloseParen); | ||
CharScanners[Char.Asterisk] = returnToken(Token.Asterisk); | ||
CharScanners[Char.Plus] = returnToken(Token.Plus); | ||
// *, *= | ||
CharScanners[Char.Asterisk] = () => { | ||
if (nextChar() !== Char.Equals) { | ||
return Token.Asterisk; | ||
} | ||
nextChar(); | ||
return Token.AsteriskEquals; | ||
}; | ||
// +, +=, ++ | ||
CharScanners[Char.Plus] = () => { | ||
if (nextChar() === Char.Plus) { | ||
nextChar(); | ||
return Token.PlusPlus; | ||
} | ||
if ($currentChar !== Char.Equals) { | ||
return Token.Plus; | ||
} | ||
nextChar(); | ||
return Token.PlusEquals; | ||
}; | ||
CharScanners[Char.Comma] = returnToken(Token.Comma); | ||
CharScanners[Char.Minus] = returnToken(Token.Minus); | ||
CharScanners[Char.Slash] = returnToken(Token.Slash); | ||
// -, -=, -- | ||
CharScanners[Char.Minus] = () => { | ||
if (nextChar() === Char.Minus) { | ||
nextChar(); | ||
return Token.MinusMinus; | ||
} | ||
if ($currentChar !== Char.Equals) { | ||
return Token.Minus; | ||
} | ||
nextChar(); | ||
return Token.MinusEquals; | ||
}; | ||
// /, /= | ||
CharScanners[Char.Slash] = () => { | ||
if (nextChar() !== Char.Equals) { | ||
return Token.Slash; | ||
} | ||
nextChar(); | ||
return Token.SlashEquals; | ||
}; | ||
CharScanners[Char.Colon] = returnToken(Token.Colon); | ||
@@ -1931,0 +2000,0 @@ CharScanners[Char.Semicolon] = returnToken(Token.Semicolon); |
@@ -51,2 +51,3 @@ export { | ||
type BinaryOperator, | ||
type AssignmentOperator, | ||
type BindingIdentifierOrPattern, | ||
@@ -65,4 +66,4 @@ type UnaryOperator, | ||
ExpressionParser, | ||
ExpressionType, | ||
type ExpressionType, | ||
parseExpression, | ||
} from './expression-parser'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
781864
15874
+ Added@aurelia/kernel@2.0.0-beta.21(transitive)
+ Added@aurelia/metadata@2.0.0-beta.21(transitive)
+ Added@aurelia/platform@2.0.0-beta.21(transitive)
- Removed@aurelia/kernel@2.0.0-beta.20(transitive)
- Removed@aurelia/metadata@2.0.0-beta.20(transitive)
- Removed@aurelia/platform@2.0.0-beta.20(transitive)