diff --git a/builds/reference/src/index.ts b/builds/reference/src/index.ts index 7b815a5a..07ee5803 100644 --- a/builds/reference/src/index.ts +++ b/builds/reference/src/index.ts @@ -24,14 +24,8 @@ import components from '@tko/utils.component' import { createElement, Fragment } from '@tko/utils.jsx' import { JsxObserver } from '@tko/utils.jsx' -import { overloadOperator } from '@tko/utils.parser' - declare const BUILD_VERSION: string -/** Overload "evil twins" with strict equivalents */ -overloadOperator('==', (a, b) => a === b) -overloadOperator('!=', (a, b) => a !== b) - const builder = new Builder({ filters, extenders: {}, diff --git a/packages/utils.parser/src/index.ts b/packages/utils.parser/src/index.ts index 89d83310..911c38e4 100644 --- a/packages/utils.parser/src/index.ts +++ b/packages/utils.parser/src/index.ts @@ -7,10 +7,3 @@ export { default as Ternary } from './Ternary' export { default as Node } from './Node' export { default as parseObjectLiteral } from './preparse' - -export function overloadOperator(op: string, fn: (a, b) => any, precedence?: number) { - operators[op] = fn - if (Number.isInteger(precedence)) { - operators[op].precedence = precedence - } -} diff --git a/packages/utils.parser/src/operators.ts b/packages/utils.parser/src/operators.ts index ad27531a..07c11328 100644 --- a/packages/utils.parser/src/operators.ts +++ b/packages/utils.parser/src/operators.ts @@ -1,4 +1,5 @@ import { unwrap } from '@tko/observable' +import { options } from '@tko/utils' export function LAMBDA() {} @@ -84,10 +85,18 @@ const operators: Operators = { // TODO: 'typeof': function (a, b) { return typeof b; }, // equality '==': function equal(a, b) { - return a == b + if (options.overloadEvilTwins) { + return a === b + } else { + return a == b + } }, '!=': function ne(a, b) { - return a != b + if (options.overloadEvilTwins) { + return a !== b + } else { + return a != b + } }, '===': function sequal(a, b) { return a === b diff --git a/packages/utils/src/options.ts b/packages/utils/src/options.ts index 2080149e..8b7b6df7 100644 --- a/packages/utils/src/options.ts +++ b/packages/utils/src/options.ts @@ -31,6 +31,10 @@ export class Options { // Modify the default attribute from `data-bind`. defaultBindingAttribute: string = 'data-bind' + // When true, == and != in binding expressions use === and !== (strict equality). + // Default true to preserve existing @tko/build.reference behavior. + overloadEvilTwins: boolean = true + // Enable/disable