Skip to content
New issue

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

babel-plugin-transform-taroapi插件对canIUse入参scheme处理问题 #14707

Closed
tangcq-code opened this issue Oct 27, 2023 · 0 comments · Fixed by #14717
Closed

babel-plugin-transform-taroapi插件对canIUse入参scheme处理问题 #14707

tangcq-code opened this issue Oct 27, 2023 · 0 comments · Fixed by #14717
Labels
F-react Framework - React T-harmony Target - 编译到 Harmony V-3 Version - 3.x
Milestone

Comments

@tangcq-code
Copy link
Contributor

相关平台

鸿蒙

复现仓库

https://github.com/xiaoyan428820/canIUseDemo.git
浏览器版本: Chrome 118
使用框架: React

复现步骤

definition.json中包含如下配置,将其传给babel-plugin-transform-taroapi插件(参数definition),页面中调用canIUse接口,例如:Taro.canIUse("live-pusher.audio-reverb-type.4")。

"live-pusher": {
  "audio-reverb-type": {
    "0": "",
    "1": "",
    "2": "",
    "3": "",
    "4": "",
    "5": "",
    "6": "",
    "7": ""
  }

}

期望结果

执行Taro.canIUse("live-pusher.audio-reverb-type.4")返回true

实际结果

执行Taro.canIUse("live-pusher.audio-reverb-type.4")返回false

环境信息

    Taro v3.6.15


  Taro CLI 3.6.15 environment info:
    System:
      OS: Windows 10 10.0.19045
    Binaries:
      Node: 16.20.2 - D:\NVM\NVMnode\node.EXE
      npm: 8.19.4 - D:\NVM\NVMnode\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.15 => 3.6.15
      @tarojs/components: 3.6.15 => 3.6.15
      @tarojs/helper: 3.6.15 => 3.6.15
      @tarojs/plugin-framework-react: workspace:* => 3.6.15
      @tarojs/plugin-platform-alipay: 3.6.15 => 3.6.15
      @tarojs/plugin-platform-h5: 3.6.15 => 3.6.15
      @tarojs/plugin-platform-jd: 3.6.15 => 3.6.15
      @tarojs/plugin-platform-qq: 3.6.15 => 3.6.15
      @tarojs/plugin-platform-swan: 3.6.15 => 3.6.15
      @tarojs/plugin-platform-tt: 3.6.15 => 3.6.15
      @tarojs/plugin-platform-weapp: 3.6.15 => 3.6.15
      @tarojs/react: 3.6.15 => 3.6.15
      @tarojs/runtime: 3.6.15 => 3.6.15
      @tarojs/shared: 3.6.15 => 3.6.15
      @tarojs/taro: 3.6.15 => 3.6.15
      @tarojs/webpack5-runner: 3.6.15 => 3.6.15
      babel-preset-taro: 3.6.15 => 3.6.15
      eslint-config-taro: 3.6.15 => 3.6.15
      react: ^18.2.0 => 18.2.0

补充信息

babel-plugin-transform-taroapi插件index.ts文件中的如下方法,处理canIUse接口scheme入参,方法中用了lodash三方库中的set函数,但set函数在处理如a.b.4这种带数字的路径时,数字属性会被处理为数组,如执行Taro.canIUse("live-pusher.audio-reverb-type.4")时,入参scheme被处理为{'live-pusher': { 'audio-reverb-type': [ <4 empty items>, true]}}, 导致后续isMatchWith方法处理返回结果是false。建议将const o = set({}, scheme, true)修改为const o = setWith({}, scheme, true, Object),使用setWith避免这种问题。
function canIUse (definition, scheme = '') {
if (!scheme) return false
const o = set({}, scheme, true,)
return isMatchWith(definition, o, (a, b) => {
if (a === '*' || b === true) return true
})
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-harmony Target - 编译到 Harmony V-3 Version - 3.x
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants