@dcloudio/uni-template-compiler 2.0.2-3061820230117002 → 2.0.2-3070320230222001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/mp.js CHANGED
@@ -54,9 +54,30 @@ const tags = {
54
54
  'editor'
55
55
  ],
56
56
  'mp-baidu': [
57
+ 'animation-video',
58
+ 'animation-view',
59
+ 'ar-camera',
60
+ 'rtc-room',
61
+ 'rtc-room-item',
62
+ 'tabs',
63
+ 'tab-item',
57
64
  'follow-swan',
58
65
  'login',
59
- 'inline-payment-panel'
66
+ 'inline-payment-panel',
67
+ 'talos-linear-gradient',
68
+ 'talos-rc-view',
69
+ 'talos-nested-scroll-view',
70
+ 'talos-nested-scroll-top-container',
71
+ 'talos-nested-scroll-bottom-container',
72
+ 'talos-waterfall-view',
73
+ 'talos-waterfall-item',
74
+ 'talos-waterfall-header',
75
+ 'talos-waterfall-footer',
76
+ 'talos-pull-refresh',
77
+ 'talos-control-container',
78
+ 'talos-na-refresh-control',
79
+ 'talos-modal',
80
+ 'talos-svg'
60
81
  ],
61
82
  'mp-weixin': [
62
83
  'page-container',
@@ -163,4 +184,4 @@ module.exports = function getCompilerOptions (platform) {
163
184
  baseCompiler,
164
185
  require(id + '/lib/uni.compiler.js')
165
186
  )
166
- }
187
+ }
@@ -1,5 +1,5 @@
1
1
  const t = require('@babel/types')
2
- const parser = require('@babel/parser')
2
+ const template = require('@babel/template').default
3
3
 
4
4
  const {
5
5
  IDENTIFIER_EVENT,
@@ -7,13 +7,15 @@ const {
7
7
  INTERNAL_EVENT_PROXY,
8
8
  ATTR_DATA_EVENT_OPTS,
9
9
  ATTR_DATA_EVENT_PARAMS,
10
- INTERNAL_SET_SYNC
10
+ INTERNAL_SET_SYNC,
11
+ INTERNAL_SET_MODEL
11
12
  } = require('../../../constants')
12
13
 
13
14
  const {
14
15
  getCode,
15
16
  customize,
16
- processMemberExpression
17
+ processMemberExpression,
18
+ replaceMemberExpression
17
19
  } = require('../../../util')
18
20
 
19
21
  const {
@@ -124,18 +126,18 @@ function parseMethod (method, state) {
124
126
  if (isForIndex(state.scoped, element)) {
125
127
  return element
126
128
  } else {
127
- extraArrayElements.push(t.stringLiteral(
129
+ extraArrayElements.push(replaceMemberExpression(t.stringLiteral(
128
130
  getExtraDataPath(getCode(processMemberExpression(element, state)),
129
131
  methodName)
130
- ))
132
+ ), state))
131
133
  }
132
134
  } else {
133
135
  extraArrayElements.push(forExtra)
134
136
  }
135
137
  } else {
136
- extraArrayElements.push(t.stringLiteral(
138
+ extraArrayElements.push(replaceMemberExpression(t.stringLiteral(
137
139
  getExtraDataPath(getCode(processMemberExpression(element, state)), methodName)
138
- ))
140
+ ), state))
139
141
  }
140
142
  return t.stringLiteral('$' + (extraArrayElements.length - 1))
141
143
  } else if ( // +1=>1
@@ -386,6 +388,13 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
386
388
  funcPath.node.params.push(t.identifier(name))
387
389
  })
388
390
  if (params.length) {
391
+ if (!isCustom) {
392
+ const bodyStatements = funcPath.get('body.body')
393
+ const returnStatement = bodyStatements[0]
394
+ if (t.isReturnStatement(returnStatement) && t.isCallExpression(returnStatement.node.argument) && returnStatement.node.argument.callee.name === INTERNAL_SET_MODEL) {
395
+ funcPath.node.body.body.unshift(template('$event=$event.target.value')())
396
+ }
397
+ }
389
398
  let argumentsName = 'arguments'
390
399
  if (funcPath.isArrowFunctionExpression()) {
391
400
  argumentsName = 'args'
@@ -395,7 +404,7 @@ function parseEvent (keyPath, valuePath, state, isComponent, isNativeOn = false,
395
404
  const paramsUid = funcPath.scope.generateDeclaredUidIdentifier().name
396
405
  const dataset = ATTR_DATA_EVENT_PARAMS.substring(5)
397
406
  const code = `var ${datasetUid}=${argumentsName}[${argumentsName}.length-1].currentTarget.dataset,${paramsUid}=${datasetUid}.${dataset.replace(/-([a-z])/, (_, str) => str.toUpperCase())}||${datasetUid}['${dataset}'],${params.map(item => `${item}=${paramsUid}.${item}`).join(',')}`
398
- funcPath.node.body.body.unshift(parser.parse(code).program.body[0])
407
+ funcPath.node.body.body.unshift(template(code)())
399
408
  }
400
409
  methods.push(addEventExpressionStatement(funcPath, state, isComponent, isNativeOn))
401
410
  }
@@ -7,13 +7,14 @@ const {
7
7
  module.exports = function processRef (paths, path, state) {
8
8
  const modelPath = paths.model
9
9
  if (modelPath) {
10
- const callbackProperty = modelPath.node.value.properties.find(property => {
10
+ const properties = modelPath.node.value.properties
11
+ const [callbackProperty] = properties.splice(properties.findIndex(property => {
11
12
  return property.key.name === 'callback'
12
- })
13
- const valueProperty = modelPath.node.value.properties.find(
13
+ }), 1)
14
+ const valueProperty = properties.find(
14
15
  property => property.key.name === 'value'
15
16
  )
16
- const exprProperty = modelPath.node.value.properties.find(
17
+ const exprProperty = properties.find(
17
18
  property => property.key.name === 'expression'
18
19
  )
19
20
 
@@ -230,6 +230,8 @@ module.exports = {
230
230
  path =>
231
231
  path.isObjectProperty() && ['on', 'nativeOn'].includes(path.node.key.name)
232
232
  )
233
+ // path is model.callback
234
+ // || path.findParent(path => path.isObjectProperty() && path.node.key.name === 'callback' && t.isFunctionExpression(path.node.value) && t.isObjectProperty(path.parentPath.parentPath) && path.parentPath.parentPath.node.key.name === 'model')
233
235
  ) {
234
236
  // event
235
237
  return path.skip()
package/lib/util.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const t = require('@babel/types')
2
2
  const babelTraverse = require('@babel/traverse').default
3
3
  const babelGenerate = require('@babel/generator').default
4
+ const babelTemplate = require('@babel/template').default
4
5
  const uniI18n = require('@dcloudio/uni-cli-i18n')
5
6
 
6
7
  const {
@@ -139,7 +140,11 @@ function processMemberProperty (node, state) {
139
140
  state.options.replaceCodes = {}
140
141
  }
141
142
  const identifier = '__$m' + (state.options.__m__++) + '__'
142
- state.options.replaceCodes[identifier] = `'+${genCode(property, true)}+'`
143
+ const code = { property }
144
+ code.toString = function () {
145
+ return `'+${genCode(this.property, true)}+'`
146
+ }
147
+ state.options.replaceCodes[identifier] = code
143
148
  if (state.computedProperty) {
144
149
  state.computedProperty[identifier] = property
145
150
  }
@@ -149,6 +154,27 @@ function processMemberProperty (node, state) {
149
154
  }
150
155
  }
151
156
 
157
+ function replaceMemberExpression (stringLiteral, state) {
158
+ let code = `'${stringLiteral.value}'`
159
+ const replaceCodes = state.options.replaceCodes
160
+ if (replaceCodes) {
161
+ const options = {}
162
+ Object.keys(replaceCodes).forEach(key => {
163
+ const newCode = code.replace(new RegExp(key.replace('$', '\\$'), 'g'), `'+%%${key}%%+'`)
164
+ if (newCode !== code) {
165
+ options[key] = replaceCodes[key].property
166
+ code = newCode
167
+ }
168
+ })
169
+ const buildRequire = babelTemplate(code)
170
+ if (Object.keys(options).length) {
171
+ const ast = buildRequire(options)
172
+ return ast.expression
173
+ }
174
+ }
175
+ return stringLiteral
176
+ }
177
+
152
178
  function processMemberExpression (element, state) {
153
179
  // item['order']=>item.order
154
180
  if (t.isMemberExpression(element)) {
@@ -332,6 +358,7 @@ module.exports = {
332
358
  return str
333
359
  }),
334
360
  processMemberExpression,
361
+ replaceMemberExpression,
335
362
  getForIndexIdentifier,
336
363
  isSimpleObjectExpression,
337
364
  hasEscapeQuote,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-template-compiler",
3
- "version": "2.0.2-3061820230117002",
3
+ "version": "2.0.2-3070320230222001",
4
4
  "description": "uni-template-compiler",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -18,9 +18,10 @@
18
18
  "license": "Apache-2.0",
19
19
  "dependencies": {
20
20
  "@babel/parser": "^7.3.3",
21
+ "@babel/template": "^7.3.3",
21
22
  "@babel/traverse": "^7.3.3",
22
23
  "@babel/types": "^7.3.3",
23
24
  "vue-template-compiler": "^2.6.10"
24
25
  },
25
- "gitHead": "ba73983f0945234511259f345277642d32a4b9f9"
26
+ "gitHead": "a9d838acc59ca170813ae09cd04890ffffd88071"
26
27
  }