微信小程序的< wxs>标签中可以直接使用getRegExp常见正则表达式对象,但是taro转换报错

js4nwp54  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(40)

相关平台

微信小程序

小程序基础库: 2.19.4
使用框架: React

复现步骤

1、在标签中使用getRegExp创建正则表达式对象
如:var REGEXP = getRegExp('^\d (.\d )?$');
2、使用taro转换异常

期望结果

正常转换

实际结果

转换异常

环境信息

$ taro info
👽 Taro v3.6.6
Taro CLI 3.6.6 environment info:
    System:
      OS: Windows 10 10.0.19045
    Binaries:
      Node: 16.19.1 - D:\software\DevEco\nodeJs16\node.EXE
      npm: 8.19.3 - D:\software\DevEco\nodeJs16\npm.CMD
    npmPackages:
      @tarojs/cli: 3.6.6 => 3.6.6
      @tarojs/components: 3.6.6 => 3.6.6
      @tarojs/helper: 3.6.6 => 3.6.6
      @tarojs/plugin-framework-react: 3.6.6 => 3.6.6
      @tarojs/plugin-platform-alipay: 3.6.6 => 3.6.6
      @tarojs/plugin-platform-h5: 3.6.6 => 3.6.6
      @tarojs/plugin-platform-jd: 3.6.6 => 3.6.6
      @tarojs/plugin-platform-qq: 3.6.6 => 3.6.6
      @tarojs/plugin-platform-swan: 3.6.6 => 3.6.6
      @tarojs/plugin-platform-tt: 3.6.6 => 3.6.6
      @tarojs/plugin-platform-weapp: 3.6.6 => 3.6.6
      @tarojs/react: 3.6.6 => 3.6.6
      @tarojs/runtime: 3.6.6 => 3.6.6
      @tarojs/shared: 3.6.6 => 3.6.6
      @tarojs/taro: 3.6.6 => 3.6.6
      @tarojs/webpack5-runner: 3.6.6 => 3.6.6
      babel-preset-taro: 3.6.6 => 3.6.6
      eslint-config-taro: 3.6.6 => 3.6.6
      react: ^18.0.0 => 18.2.0
rqmkfv5c

rqmkfv5c2#

  1. getRegExp为微信小程序wxs特殊的语法:https://developers.weixin.qq.com/miniprogram/dev/reference/wxs/06datatype.html#regexp
  2. 需要采用babel将
var REGEXP = getRegExp('^\d+(\.\d+)?$');

转换为普通的js正则调用

var REGEXP = new RegExp('^\d+(\.\d+)?$', 'g');

相关问题