We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Currently the if directive is implemented by the following function:
export function ifComparator(params: IParamsMap, rawCondition: string): boolean { const keys = Object.keys(params); const values = keys.reduce((v, key) => v.concat(params[key]), []); const comparator = new Function(...keys, `return ${rawCondition};`); return comparator(...values); }
v.concat may cause wrong result if the value type is Array. Just a little snippet:
v.concat
const testObj = { a: 1, b: [0, 2, 3] }; const keys = Object.keys(testObj); const values = keys.reduce((v, key) => v.concat(testObj[key]), []);
keys is ["a", "b"] values is [1, 0, 2, 3] (new Function(...keys, 'return b;'))(...values) will return 0, and this is an unexpected result.
keys
["a", "b"]
values
[1, 0, 2, 3]
(new Function(...keys, 'return b;'))(...values)
0
A more robust way is to use push instead of concat.
push
concat
The text was updated successfully, but these errors were encountered:
🐛 Support non-primitive params
76cdec3
@scarletsky 这个情况倒是的确没想到...
数组的问题已经修复了,补丁对应版本为1.1.4。
关于这个concat的问题,其实直接用map就行了:
preprocessor-loader/src/filter.ts
Line 109 in 40b3e13
Sorry, something went wrong.
@afterwind-io 哈哈,map 也可以。我也是刚好碰到打包出现异常的时候才留意到这个问题。
afterwind-io
Successfully merging a pull request may close this issue.
Currently the if directive is implemented by the following function:
v.concat
may cause wrong result if the value type is Array. Just a little snippet:keys
is["a", "b"]
values
is[1, 0, 2, 3]
(new Function(...keys, 'return b;'))(...values)
will return0
, and this is an unexpected result.A more robust way is to use
push
instead ofconcat
.The text was updated successfully, but these errors were encountered: