mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
@@ -25,7 +25,7 @@
|
||||
// Misc types, constants and helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const RESERVED_WORDS = "true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,typeof,eval,void,Math,RegExp,Array,Object,Date".split(
|
||||
const RESERVED_WORDS = "true,false,NaN,null,undefined,debugger,console,window,in,instanceof,new,function,return,this,eval,void,Math,RegExp,Array,Object,Date".split(
|
||||
","
|
||||
);
|
||||
|
||||
@@ -77,7 +77,9 @@ const STATIC_TOKEN_MAP: { [key: string]: TKind } = {
|
||||
")": "RIGHT_PAREN"
|
||||
};
|
||||
|
||||
const OPERATORS = ".,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%".split(",");
|
||||
// note that the space after typeof is relevant. It makes sure that the formatted
|
||||
// expression has a space after typeof
|
||||
const OPERATORS = ".,===,==,+,!==,!=,!,||,&&,>=,>,<=,<,?,-,*,/,%,typeof ".split(",");
|
||||
|
||||
type Tokenizer = (expr: string) => Token | false;
|
||||
|
||||
@@ -160,9 +162,9 @@ const tokenizeOperator: Tokenizer = function(expr) {
|
||||
const TOKENIZERS = [
|
||||
tokenizeString,
|
||||
tokenizeNumber,
|
||||
tokenizeOperator,
|
||||
tokenizeSymbol,
|
||||
tokenizeStatic,
|
||||
tokenizeOperator
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,9 @@ describe("tokenizer", () => {
|
||||
{ type: "OPERATOR", value: "!==" },
|
||||
{ type: "OPERATOR", value: "!=" }
|
||||
]);
|
||||
expect(tokenize("typeof a")).toEqual([
|
||||
{"type": "OPERATOR", "value": "typeof "}, {"type": "SYMBOL", "value": "a"}
|
||||
]);
|
||||
});
|
||||
|
||||
test("strings", () => {
|
||||
@@ -112,6 +115,7 @@ describe("expression evaluation", () => {
|
||||
expect(compileExpr("!flag", {})).toBe("!context['flag']");
|
||||
expect(compileExpr("-3", {})).toBe("-3");
|
||||
expect(compileExpr("-a", {})).toBe("-context['a']");
|
||||
expect(compileExpr("typeof a", {})).toBe("typeof context['a']");
|
||||
});
|
||||
|
||||
test("various binary operators", () => {
|
||||
|
||||
Reference in New Issue
Block a user