hash
stringlengths 40
40
| date
stringdate 2018-04-08 22:09:22
2025-02-28 12:07:04
| author
stringclasses 198
values | commit_message
stringlengths 7
121
| is_merge
bool 1
class | masked_commit_message
stringlengths 2
112
| type
stringclasses 8
values | git_diff
stringlengths 224
25.2M
⌀ |
|---|---|---|---|---|---|---|---|
e90efdf4e78172b09567f8b13969fdc3ad62a3f4
|
2019-03-11 20:28:00
|
littly
|
feat(babel-plugin-transform-taroapi): 加入taroapi转换插件
| false
|
加入taroapi转换插件
|
feat
|
diff --git a/lerna.json b/lerna.json
index 6dc1592d8494..7d09964da0d6 100644
--- a/lerna.json
+++ b/lerna.json
@@ -34,6 +34,7 @@
"packages/postcss-pxtransform",
"packages/postcss-unit-transform",
"packages/babel-plugin-transform-jsx-to-stylesheet",
+ "packages/babel-plugin-transform-taroapi",
"packages/taro-mobx-prop-types",
"packages/taro-mobx",
"packages/taro-mobx-common",
diff --git a/packages/babel-plugin-transform-taroapi/jest.config.js b/packages/babel-plugin-transform-taroapi/jest.config.js
new file mode 100644
index 000000000000..758fa1330e87
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/jest.config.js
@@ -0,0 +1,4 @@
+module.exports = {
+ preset: 'ts-jest',
+ testEnvironment: 'node'
+}
diff --git a/packages/babel-plugin-transform-taroapi/package.json b/packages/babel-plugin-transform-taroapi/package.json
new file mode 100644
index 000000000000..c4103b979878
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/package.json
@@ -0,0 +1,27 @@
+{
+ "name": "babel-plugin-transform-taroapi",
+ "version": "1.2.9",
+ "main": "dist/index.js",
+ "license": "MIT",
+ "scripts": {
+ "build": "npm run test && tsc",
+ "dev": "jest --watch -u",
+ "prepack": "npm run build",
+ "test": "jest"
+ },
+ "devDependencies": {
+ "@types/babel-core": "^6.25.5",
+ "@types/babel-traverse": "^6.25.4",
+ "@types/babel-types": "^7.0.4",
+ "@types/jest": "^23.3.13",
+ "@types/node": "^10.12.18",
+ "babel-core": "^6.26.3",
+ "babel-types": "^6.26.0",
+ "jest": "23.6.0",
+ "ts-jest": "^23.10.5",
+ "tslint": "^5.12.1",
+ "tslint-config-prettier": "^1.17.0",
+ "tslint-config-standard": "^8.0.1",
+ "typescript": "^3.2.4"
+ }
+}
diff --git a/packages/babel-plugin-transform-taroapi/src/__tests__/__snapshots__/index-test.ts.snap b/packages/babel-plugin-transform-taroapi/src/__tests__/__snapshots__/index-test.ts.snap
new file mode 100644
index 000000000000..4ba1d3557fa0
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/src/__tests__/__snapshots__/index-test.ts.snap
@@ -0,0 +1,53 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should leave other apis untouched 1`] = `
+"
+import Taro from '@tarojs/taro-h5';
+Taro.noop;"
+`;
+
+exports[`should move static apis under "Taro" 1`] = `
+"
+import Taro from '@tarojs/taro-h5';
+Taro.noop;
+Taro.noop();"
+`;
+
+exports[`should not go wrong when use an api twice 1`] = `
+"
+import { createAnimation as _createAnimation } from '@tarojs/taro-h5';
+const animation = _createAnimation({
+ duration: dura * 1000,
+ timingFunction: 'linear'
+});
+const resetAnimation = _createAnimation({
+ duration: 0,
+ timingFunction: 'linear'
+});"
+`;
+
+exports[`should not import taro duplicatly 1`] = `
+"
+import Taro, { createAnimation as _createAnimation } from \\"@tarojs/taro-h5\\";
+
+Taro.Component;
+_createAnimation();
+Taro.initPxTransform();"
+`;
+
+exports[`should transform fullfilled apis to named import 1`] = `
+"
+import { request as _request, createAnimation as _createAnimation, createSelectorQuery as _createSelectorQuery, connectSocket as _connectSocket, onSocketOpen as _onSocketOpen, onSocketError as _onSocketError, sendSocketMessage as _sendSocketMessage, onSocketMessage as _onSocketMessage, closeSocket as _closeSocket, onSocketClose as _onSocketClose, setStorage as _setStorage, setStorageSync as _setStorageSync, getStorage as _getStorage, getStorageSync as _getStorageSync, getStorageInfo as _getStorageInfo, getStorageInfoSync as _getStorageInfoSync, removeStorage as _removeStorage, removeStorageSync as _removeStorageSync, clearStorage as _clearStorage, clearStorageSync as _clearStorageSync, showToast as _showToast, hideToast as _hideToast, showLoading as _showLoading, hideLoading as _hideLoading, showModal as _showModal, showActionSheet as _showActionSheet, initTabBarApis as _initTabBarApis, getSystemInfo as _getSystemInfo, getSystemInfoSync as _getSystemInfoSync, getNetworkType as _getNetworkType, onNetworkStatusChange as _onNetworkStatusChange, arrayBufferToBase64 as _arrayBufferToBase, base64ToArrayBuffer as _base64ToArrayBuffer, makePhoneCall as _makePhoneCall, setNavigationBarTitle as _setNavigationBarTitle } from '@tarojs/taro-h5';
+_request();_createAnimation();_createSelectorQuery();_connectSocket();_onSocketOpen();_onSocketError();_sendSocketMessage();_onSocketMessage();_closeSocket();_onSocketClose();_setStorage();_setStorageSync();_getStorage();_getStorageSync();_getStorageInfo();_getStorageInfoSync();_removeStorage();_removeStorageSync();_clearStorage();_clearStorageSync();_showToast();_hideToast();_showLoading();_hideLoading();_showModal();_showActionSheet();_initTabBarApis();_getSystemInfo();_getSystemInfoSync();_getNetworkType();_onNetworkStatusChange();_arrayBufferToBase();_base64ToArrayBuffer();_makePhoneCall();_setNavigationBarTitle();"
+`;
+
+exports[`should work! 1`] = `
+"
+import Taro, { setStorage as _setStorage, getStorage as _getStorage } from '@tarojs/taro-h5';
+Taro.initPxTransform(Taro.param);
+Taro.initPxTransform();
+Taro.initPxTransform();
+_getStorage();
+_setStorage();
+export { Taro };"
+`;
diff --git a/packages/babel-plugin-transform-taroapi/src/__tests__/index-test.ts b/packages/babel-plugin-transform-taroapi/src/__tests__/index-test.ts
new file mode 100644
index 000000000000..d12f1d6ff4e2
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/src/__tests__/index-test.ts
@@ -0,0 +1,143 @@
+import * as apis from '@tarojs/taro-h5/dist/taroApis'
+import * as babel from 'babel-core'
+import * as t from 'babel-types'
+
+import plugin from '../'
+
+const pluginOptions = [
+ plugin,
+ {
+ apis,
+ packageName: '@tarojs/taro-h5'
+ }
+]
+
+const getNamedImports = (importSpecifiers: (t.ImportSpecifier | t.ImportDefaultSpecifier | t.ImportNamespaceSpecifier)[]) => {
+ return importSpecifiers.reduce((prev, curr: t.ImportSpecifier) => {
+ if (t.isImportSpecifier(curr)) {
+ prev.add(curr.imported.name)
+ }
+ return prev
+ }, new Set())
+}
+
+it('should work!', function () {
+ const code = `
+ import Taro, { setStorage, initPxTransform, param } from '@tarojs/taro-h5';
+ initPxTransform(param)
+ Taro.initPxTransform()
+ Taro.initPxTransform()
+ Taro['getStorage']()
+ setStorage()
+ export { Taro }
+ `
+ const result = babel.transform(code, {plugins: [pluginOptions]});
+ expect(result.code).toMatchSnapshot();
+});
+
+it('should transform fullfilled apis to named import', function () {
+ const code = `
+ import Taro from '@tarojs/taro-h5'
+ ${Array.from(apis).map(api => `Taro.${api}();`)
+ .join('')}
+ `
+ const result = babel.transform(code, { plugins: [pluginOptions] })
+ expect(result.code).toMatchSnapshot();
+
+ const ast = result.ast as t.File
+ const body = ast.program.body as [t.ImportDeclaration, t.ExpressionStatement]
+ expect(t.isImportDeclaration(body[0])).toBeTruthy()
+
+ const namedImports = getNamedImports(body[0].specifiers)
+ expect(namedImports).toEqual(new Set(apis))
+})
+
+it('should leave other apis untouched', function () {
+ const code = `
+ import Taro from '@tarojs/taro-h5'
+ Taro.noop
+ `
+ const result = babel.transform(code, { plugins: [pluginOptions] })
+ expect(result.code).toMatchSnapshot();
+
+ const ast = result.ast as t.File
+ const body = ast.program.body as [t.ImportDeclaration, t.ExpressionStatement]
+ expect(t.isImportDeclaration(body[0])).toBeTruthy()
+ expect(t.isExpressionStatement(body[1])).toBeTruthy()
+ const defaultImport = body[0].specifiers.find(v => t.isImportDefaultSpecifier(v))
+ expect(defaultImport).toBeTruthy()
+
+ const taroName = defaultImport!.local.name
+ const namedImports = getNamedImports(body[0].specifiers)
+ expect(namedImports).toEqual(new Set())
+ expect(t.isMemberExpression(body[1].expression)).toBeTruthy()
+ expect((body[1].expression as t.MemberExpression)).toMatchObject(t.memberExpression(
+ t.identifier(taroName),
+ t.identifier('noop')
+ ))
+})
+
+it('should move static apis under "Taro"', function () {
+ const code = `
+ import { noop } from '@tarojs/taro-h5';
+ noop;
+ noop();
+ `
+
+ const result = babel.transform(code, { plugins: [pluginOptions] })
+ expect(result.code).toMatchSnapshot();
+
+ const ast = result.ast as t.File
+ const body = ast.program.body as [t.ImportDeclaration, t.ExpressionStatement]
+ expect(t.isImportDeclaration(body[0])).toBeTruthy()
+ expect(t.isExpressionStatement(body[1])).toBeTruthy()
+ const defaultImport = body[0].specifiers.find(v => t.isImportDefaultSpecifier(v))
+ expect(defaultImport).toBeTruthy()
+
+ const taroName = defaultImport!.local.name
+ let memberExpression = body[1].expression
+ if (t.isCallExpression(body[1])) {
+ memberExpression = (body[1].expression as t.CallExpression).callee
+ }
+ expect(memberExpression).toMatchObject(t.memberExpression(
+ t.identifier(taroName),
+ t.identifier('noop')
+ ))
+})
+
+it('should not import taro duplicatly', function () {
+ const code = `
+ import { Component } from "@tarojs/taro-h5";
+ import Taro from '@tarojs/taro-h5';
+ Component
+ Taro.createAnimation()
+ Taro.initPxTransform()
+ `
+
+ const result = babel.transform(code, { plugins: [pluginOptions] })
+ expect(result.code).toMatchSnapshot();
+
+ const ast = result.ast as t.File
+ const body = ast.program.body as [t.ImportDeclaration, t.ExpressionStatement, t.ExpressionStatement]
+ expect(t.isImportDeclaration(body[0])).toBeTruthy()
+ expect(t.isExpressionStatement(body[1])).toBeTruthy()
+ expect(t.isExpressionStatement(body[2])).toBeTruthy()
+})
+
+it('should not go wrong when use an api twice', function () {
+ const code = `
+ import Taro from '@tarojs/taro-h5';
+ const animation = Taro.createAnimation({
+ duration: dura * 1000,
+ timingFunction: 'linear'
+ })
+ const resetAnimation = Taro.createAnimation({
+ duration: 0,
+ timingFunction: 'linear'
+ })
+ `
+ expect(() => {
+ const result = babel.transform(code, { plugins: [ pluginOptions ]})
+ expect(result.code).toMatchSnapshot();
+ }).not.toThrowError()
+})
\ No newline at end of file
diff --git a/packages/babel-plugin-transform-taroapi/src/index.ts b/packages/babel-plugin-transform-taroapi/src/index.ts
new file mode 100644
index 000000000000..e81392397f65
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/src/index.ts
@@ -0,0 +1,111 @@
+import { VisitNodeFunction } from 'babel-traverse';
+import { types as Types, PluginObj } from 'babel-core';
+
+const plugin = function (babel: {
+ types: typeof Types;
+}): PluginObj {
+ const t = babel.types
+ let taroName: string = 'Taro'
+ let needDefault = false
+ let isTaroApiImported = false
+ const invokedApis: Map<string, string> = new Map()
+
+ const getTaroName: VisitNodeFunction<{}, Types.ImportDefaultSpecifier> = (ast) => {
+ taroName = ast.node.local.name
+ }
+
+ return {
+ name: 'babel-plugin-transform-taro-api',
+ visitor: {
+ ImportDeclaration (ast, state) {
+ const apis = state.opts.apis
+ const packageName = state.opts.packageName
+ if (ast.node.source.value !== packageName) return
+
+ ast.traverse({
+ ImportDefaultSpecifier: getTaroName,
+ ImportSpecifier: ast => {
+ const propertyName = ast.node.imported.name
+ if (apis.has(propertyName)) { // 记录api名字
+ ast.scope.rename(ast.node.local.name)
+ invokedApis.set(propertyName, ast.node.local.name)
+ } else { // 如果是未实现的api 改成Taro.xxx
+ const binding = ast.scope.getBinding(propertyName)!
+ binding.referencePaths.forEach(reference => {
+ reference.replaceWith(
+ t.memberExpression(
+ t.identifier(taroName),
+ t.identifier(propertyName)
+ )
+ )
+ })
+ }
+ }
+ })
+ },
+ MemberExpression (ast, state) {
+ const apis = state.opts.apis
+ const isTaro = t.isIdentifier(ast.node.object, { name: taroName })
+ const property = ast.node.property
+ let propertyName: string | null = null
+ let propName = 'name'
+
+ if (!isTaro) return
+
+ // 兼容一下 Taro['xxx']
+ if (t.isStringLiteral(property)) {
+ propName = 'value'
+ }
+ propertyName = property[propName]
+
+ if (!propertyName) return
+
+ // 同一api使用多次, 读取变量名
+ if (apis.has(propertyName)) {
+ let identifier: Types.Identifier
+ if (invokedApis.has(propertyName)) {
+ identifier = t.identifier(invokedApis.get(propertyName)!)
+ } else {
+ const newPropertyName = ast.scope.generateUid(propertyName)
+ invokedApis.set(propertyName, newPropertyName)
+ /* 未绑定作用域 */
+ identifier = t.identifier(newPropertyName)
+ }
+ ast.replaceWith(identifier)
+ } else {
+ needDefault = true
+ }
+ },
+ Program: {
+ enter (ast, state) {
+ needDefault = false
+ isTaroApiImported = false
+ invokedApis.clear()
+ },
+ exit (ast, state) {
+ ast.traverse({
+ ImportDeclaration (ast) {
+ const packageName = state.opts.packageName
+ const isImportingTaroApi = ast.node.source.value === packageName
+ if (!isImportingTaroApi) return
+ if (isTaroApiImported) return ast.remove()
+ isTaroApiImported = true
+ const namedImports = Array.from(invokedApis.entries()).map(([imported, local]) => t.importSpecifier(t.identifier(local), t.identifier(imported)))
+ if (needDefault) {
+ const defaultImport = t.importDefaultSpecifier(t.identifier(taroName))
+ ast.node.specifiers = [
+ defaultImport,
+ ...namedImports
+ ]
+ needDefault = false
+ } else {
+ ast.node.specifiers = namedImports
+ }
+ }
+ })
+ }
+ }
+ }
+ }
+}
+export default plugin
diff --git a/packages/babel-plugin-transform-taroapi/tsconfig.json b/packages/babel-plugin-transform-taroapi/tsconfig.json
new file mode 100644
index 000000000000..6e9af3df1e4c
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/tsconfig.json
@@ -0,0 +1,25 @@
+{
+ "compilerOptions": {
+ "allowSyntheticDefaultImports": true,
+ "allowJs": true,
+ "baseUrl": ".",
+ "experimentalDecorators": true,
+ "lib": ["esnext", "dom"],
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "noImplicitAny": false,
+ "noUnusedLocals": true,
+ "outDir": "dist/",
+ "preserveConstEnums": true,
+ "removeComments": false,
+ "rootDir": "./src",
+ "sourceMap": false,
+ "strictNullChecks": true,
+ "target": "es2015",
+ "traceResolution": false,
+ "types": ["jest"]
+ },
+ "include": [
+ "./src/index.ts"
+ ]
+}
diff --git a/packages/babel-plugin-transform-taroapi/tslint.json b/packages/babel-plugin-transform-taroapi/tslint.json
new file mode 100644
index 000000000000..4b9556f6f42d
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/tslint.json
@@ -0,0 +1,31 @@
+{
+ "extends": [
+ "tslint-config-standard",
+ "tslint-config-prettier"
+ ],
+ "defaultSeverity": "error",
+ "rules": {
+ "ban-types": false,
+ "forin": false,
+ "interface-name": false,
+ "member-access": false,
+ "no-bitwise": false,
+ "no-conditional-assignment": false,
+ "no-console": false,
+ "no-empty": false,
+ "no-object-literal-type-assertion": false,
+ "no-string-literal": false,
+ "no-var-keyword": true,
+ "object-literal-key-quotes": [ false, "as-needed" ],
+ "object-literal-sort-keys": false,
+ "one-variable-per-declaration": false,
+ "ordered-imports": false,
+ "prefer-for-of": false,
+ "quotemark": [ true, "single", "avoid-escape", "jsx-double" ],
+ "semicolon": [ false, "never" ],
+ "space-before-function-paren": false,
+ "trailing-comma": [ true, { "multiline": "never", "singleline": "never" } ],
+ "variable-name": [ true, "allow-leading-underscore", "ban-keywords" ],
+ "prefer-const": true
+ }
+}
\ No newline at end of file
diff --git a/packages/babel-plugin-transform-taroapi/types.d.ts b/packages/babel-plugin-transform-taroapi/types.d.ts
new file mode 100644
index 000000000000..c99072f042c0
--- /dev/null
+++ b/packages/babel-plugin-transform-taroapi/types.d.ts
@@ -0,0 +1,5 @@
+declare module "@tarojs/taro-h5/dist/taroApis" {
+ export const apis: {
+ [key: string]: boolean
+ }
+}
diff --git a/yarn.lock b/yarn.lock
index e8f094a649d3..fd6c75dfde26 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -951,6 +951,14 @@ any-observable@^0.3.0:
version "0.3.0"
resolved "https://registry.npmjs.org/any-observable/-/any-observable-0.3.0.tgz#af933475e5806a67d0d7df090dd5e8bef65d119b"
+anymatch@^1.3.0:
+ version "1.3.2"
+ resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a"
+ integrity sha512-0XNayC8lTHQ2OI8aljNCN3sSx6hsr/1+rlcDAotXJR7C1oZZHCNsfpbKwMjRA3Uqb5tF1Rae2oloTr4xpq+WjA==
+ dependencies:
+ micromatch "^2.1.5"
+ normalize-path "^2.0.0"
+
anymatch@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb"
@@ -1167,6 +1175,28 @@ aws4@^1.8.0:
version "1.8.0"
resolved "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
+babel-cli@^6.26.0:
+ version "6.26.0"
+ resolved "https://registry.yarnpkg.com/babel-cli/-/babel-cli-6.26.0.tgz#502ab54874d7db88ad00b887a06383ce03d002f1"
+ integrity sha1-UCq1SHTX24itALiHoGODzgPQAvE=
+ dependencies:
+ babel-core "^6.26.0"
+ babel-polyfill "^6.26.0"
+ babel-register "^6.26.0"
+ babel-runtime "^6.26.0"
+ commander "^2.11.0"
+ convert-source-map "^1.5.0"
+ fs-readdir-recursive "^1.0.0"
+ glob "^7.1.2"
+ lodash "^4.17.4"
+ output-file-sync "^1.1.2"
+ path-is-absolute "^1.0.1"
+ slash "^1.0.0"
+ source-map "^0.5.6"
+ v8flags "^2.1.1"
+ optionalDependencies:
+ chokidar "^1.6.1"
+
[email protected], babel-code-frame@^6.22.0, babel-code-frame@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
@@ -1657,7 +1687,7 @@ babel-plugin-transform-strict-mode@^6.24.1:
babel-runtime "^6.22.0"
babel-types "^6.24.1"
[email protected]:
[email protected], babel-polyfill@^6.26.0:
version "6.26.0"
resolved "https://registry.npmjs.org/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153"
dependencies:
@@ -2306,6 +2336,22 @@ [email protected]:
lodash.reject "^4.4.0"
lodash.some "^4.4.0"
+chokidar@^1.6.1:
+ version "1.7.0"
+ resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
+ integrity sha1-eY5ol3gVHIB2tLNg5e3SjNortGg=
+ dependencies:
+ anymatch "^1.3.0"
+ async-each "^1.0.0"
+ glob-parent "^2.0.0"
+ inherits "^2.0.1"
+ is-binary-path "^1.0.0"
+ is-glob "^2.0.0"
+ path-is-absolute "^1.0.0"
+ readdirp "^2.0.0"
+ optionalDependencies:
+ fsevents "^1.0.0"
+
chokidar@^2.0.0, chokidar@^2.0.2:
version "2.0.4"
resolved "https://registry.npmjs.org/chokidar/-/chokidar-2.0.4.tgz#356ff4e2b0e8e43e322d18a372460bbcf3accd26"
@@ -2620,7 +2666,7 @@ [email protected], commander@~2.17.1:
version "2.17.1"
resolved "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"
-commander@^2.14.1, commander@^2.15.1, commander@^2.18.0, commander@^2.9.0:
+commander@^2.11.0, commander@^2.14.1, commander@^2.15.1, commander@^2.18.0, commander@^2.9.0:
version "2.19.0"
resolved "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
@@ -3001,7 +3047,7 @@ conventional-recommended-bump@^1.2.1:
meow "^3.3.0"
object-assign "^4.0.1"
-convert-source-map@^1.1.0, convert-source-map@^1.1.1, convert-source-map@^1.5.1:
+convert-source-map@^1.1.0, convert-source-map@^1.1.1, convert-source-map@^1.5.0, convert-source-map@^1.5.1:
version "1.6.0"
resolved "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.6.0.tgz#51b537a8c43e0f04dec1993bffcdd504e758ac20"
dependencies:
@@ -4759,10 +4805,23 @@ fs-minipass@^1.2.5:
dependencies:
minipass "^2.2.1"
+fs-readdir-recursive@^1.0.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27"
+ integrity sha512-GNanXlVr2pf02+sPN40XN8HG+ePaNcvM0q5mZBd668Obwb0yD5GiUbZOFgwn8kGMY6I3mdyDJzieUy3PTYyTRA==
+
fs.realpath@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
+fsevents@^1.0.0:
+ version "1.2.7"
+ resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.7.tgz#4851b664a3783e52003b3c66eb0eee1074933aa4"
+ integrity sha512-Pxm6sI2MeBD7RdD12RYsqaP0nMiwx8eZBXCa6z2L+mRHm2DYrOYwihmhjpkdjUHwQhslWQjRpEgNq4XvBmaAuw==
+ dependencies:
+ nan "^2.9.2"
+ node-pre-gyp "^0.10.0"
+
fsevents@^1.2.2:
version "1.2.4"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-1.2.4.tgz#f41dcb1af2582af3692da36fc55cbd8e1041c426"
@@ -5172,7 +5231,7 @@ [email protected]:
version "4.1.11"
resolved "http://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
-graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6:
+graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.4, graceful-fs@^4.1.6:
version "4.1.15"
resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
@@ -7172,7 +7231,7 @@ methods@~1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
-micromatch@^2.3.11, micromatch@^2.3.7:
+micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7:
version "2.3.11"
resolved "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
dependencies:
@@ -7572,7 +7631,7 @@ normalize-package-data@^2.3.0, normalize-package-data@^2.3.2, normalize-package-
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"
-normalize-path@^2.0.1, normalize-path@^2.1.1:
+normalize-path@^2.0.0, normalize-path@^2.0.1, normalize-path@^2.1.1:
version "2.1.1"
resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9"
dependencies:
@@ -7876,6 +7935,15 @@ osenv@0, osenv@^0.1.4:
os-homedir "^1.0.0"
os-tmpdir "^1.0.0"
+output-file-sync@^1.1.2:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/output-file-sync/-/output-file-sync-1.1.2.tgz#d0a33eefe61a205facb90092e826598d5245ce76"
+ integrity sha1-0KM+7+YaIF+suQCS6CZZjVJFznY=
+ dependencies:
+ graceful-fs "^4.1.4"
+ mkdirp "^0.5.1"
+ object-assign "^4.1.0"
+
p-cancelable@^0.3.0:
version "0.3.0"
resolved "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.3.0.tgz#b9e123800bcebb7ac13a479be195b507b98d30fa"
@@ -10646,6 +10714,11 @@ use@^3.1.0:
version "3.1.1"
resolved "https://registry.npmjs.org/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
+user-home@^1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190"
+ integrity sha1-K1viOjK2Onyd640PKNSFcko98ZA=
+
util-deprecate@^1.0.1, util-deprecate@~1.0.1:
version "1.0.2"
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
@@ -10685,6 +10758,13 @@ uuid@^3.0.1, uuid@^3.3.2:
version "3.3.2"
resolved "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
+v8flags@^2.1.1:
+ version "2.1.1"
+ resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.1.1.tgz#aab1a1fa30d45f88dd321148875ac02c0b55e5b4"
+ integrity sha1-qrGh+jDUX4jdMhFIh1rALAtV5bQ=
+ dependencies:
+ user-home "^1.1.1"
+
vali-date@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/vali-date/-/vali-date-1.0.0.tgz#1b904a59609fb328ef078138420934f6b86709a6"
|
c6b73cdc407ad4c2674d42763848f9f15ace8204
|
2018-08-07 18:02:27
|
luckyadam
|
feat(taro): 更新 Taro typings
| false
|
更新 Taro typings
|
feat
|
diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts
index bb6aecce9325..ef6134940929 100644
--- a/packages/taro/types/index.d.ts
+++ b/packages/taro/types/index.d.ts
@@ -77,10 +77,12 @@ declare namespace Taro {
}
- function getEnv(): 'WEAPP' | 'WEB' | 'RN';
+ function getEnv(): ENV_TYPE.WEAPP | ENV_TYPE.WEB | ENV_TYPE.RN;
function render(component: Component | JSX.Element, element: Element | null)
+ function pxTransform(size: number): string
+
/**
*
* 微信端能力
|
dfa9c1070713286df1d61d01e1b5ba155af32a8a
|
2019-10-29 14:23:17
|
luckyadam
|
feat(taro-mini-runner): 生成多端类型文件
| false
|
生成多端类型文件
|
feat
|
diff --git a/packages/taro-mini-runner/src/index.ts b/packages/taro-mini-runner/src/index.ts
index acfd823b6ee4..52c2fc7998d3 100644
--- a/packages/taro-mini-runner/src/index.ts
+++ b/packages/taro-mini-runner/src/index.ts
@@ -3,7 +3,10 @@ import * as webpack from 'webpack'
import { IBuildConfig } from './utils/types'
import { printBuildError, bindProdLogger } from './utils/logHelper'
-import MiniPlugin from './plugins/miniPlugin'
+import MiniPlugin, { Targets } from './plugins/MiniPlugin'
+import { MINI_APP_FILES } from './utils/constants'
+
+const extensions = ['.ts', '.tsx', '.js', '.jsx']
export default function build (config: IBuildConfig) {
const compilePlugins = config.plugins
@@ -44,14 +47,14 @@ export default function build (config: IBuildConfig) {
}]
},
{
- test: /\.(scss|wxss|acss|)$/,
+ test: /\.(scss|wxss|acss|ttss|acss|)$/,
include: /src/,
use: [
{
loader: require.resolve('file-loader'),
options: {
useRelativePath: true,
- name: `[path][name].wxss`,
+ name: `[path][name]${MINI_APP_FILES[config.buildAdapter].STYLE}`,
context: config.sourceDir
}
},
diff --git a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts
index 352e84e0622f..10a829d2af72 100644
--- a/packages/taro-mini-runner/src/plugins/MiniPlugin.ts
+++ b/packages/taro-mini-runner/src/plugins/MiniPlugin.ts
@@ -14,7 +14,7 @@ import * as t from 'babel-types'
import traverse from 'babel-traverse'
import { Config as IConfig } from '@tarojs/taro'
-import { REG_TYPESCRIPT, BUILD_TYPES, PARSE_AST_TYPE } from '../utils/constants'
+import { REG_TYPESCRIPT, BUILD_TYPES, PARSE_AST_TYPE, MINI_APP_FILES } from '../utils/constants'
import { traverseObjectNode, resolveScriptPath, buildUsingComponents } from '../utils'
import TaroTemplatePlugin from './TaroTemplatePlugin'
@@ -23,14 +23,14 @@ import TaroLoadChunksPlugin from './TaroLoadChunksPlugin'
interface IMiniPluginOptions {
appEntry?: string,
buildAdapter: BUILD_TYPES,
- commonChunks?: string[]
+ commonChunks: string[]
}
export interface ITaroFileInfo {
[key: string]: {
type: PARSE_AST_TYPE,
config: IConfig,
- wxml?: string,
+ template?: string,
code?: string
}
}
@@ -41,19 +41,14 @@ const PLUGIN_NAME = 'MiniPlugin'
const taroFileTypeMap: ITaroFileInfo = {}
-export const createTarget = function createTarget(name) {
- const target = (compiler: webpack.compiler.Compiler) => {
+export const createTarget = function createTarget (name) {
+ return (compiler: webpack.compiler.Compiler) => {
const { options } = compiler
new TaroTemplatePlugin().apply(compiler)
new FunctionModulePlugin(options.output).apply(compiler)
new NodeSourcePlugin(options.node).apply(compiler)
new LoaderTargetPlugin('web').apply(compiler)
- }
-
- const creater = new Function(
- `var t = arguments[0]; return function ${name}(c) { return t(c); }`
- );
- return creater(target)
+ }
}
export const Targets = {
@@ -209,7 +204,7 @@ export default class MiniPlugin {
taroFileTypeMap[this.appEntry] = {
type: PARSE_AST_TYPE.ENTRY,
config: configObj,
- wxml: transformResult.template,
+ template: transformResult.template,
code: transformResult.code
}
this.pages = new Set([
@@ -235,7 +230,7 @@ export default class MiniPlugin {
taroFileTypeMap[file.path] = {
type: isRoot ? PARSE_AST_TYPE.PAGE : PARSE_AST_TYPE.COMPONENT,
config: merge({}, buildUsingComponents(file.path, {}, transformResult.components),configObj),
- wxml: transformResult.template,
+ template: transformResult.template,
code: transformResult.code
}
let depComponents = transformResult.components
@@ -268,16 +263,17 @@ export default class MiniPlugin {
}
generateMiniFiles (compilation: webpack.compilation.Compilation) {
+ const { buildAdapter } = this.options
Object.keys(taroFileTypeMap).forEach(item => {
const relativePath = item.replace(this.sourceDir, '')
const extname = path.extname(item)
- const wxmlPath = relativePath.replace(extname, '.wxml')
- const jsonPath = relativePath.replace(extname, '.json')
+ const templatePath = relativePath.replace(extname, MINI_APP_FILES[buildAdapter].TEMPL)
+ const jsonPath = relativePath.replace(extname, MINI_APP_FILES[buildAdapter].CONFIG)
const itemInfo = taroFileTypeMap[item]
if (itemInfo.type !== PARSE_AST_TYPE.ENTRY) {
- compilation.assets[wxmlPath] = {
- size: () => itemInfo.wxml!.length,
- source: () => itemInfo.wxml
+ compilation.assets[templatePath] = {
+ size: () => itemInfo.template!.length,
+ source: () => itemInfo.template
}
}
const jsonStr = JSON.stringify(itemInfo.config)
diff --git a/packages/taro-mini-runner/src/utils/constants.ts b/packages/taro-mini-runner/src/utils/constants.ts
index 2e416f235903..6c830787a890 100644
--- a/packages/taro-mini-runner/src/utils/constants.ts
+++ b/packages/taro-mini-runner/src/utils/constants.ts
@@ -20,6 +20,91 @@ export const enum BUILD_TYPES {
QQ = 'qq'
}
+export const enum TEMPLATE_TYPES {
+ WEAPP = '.wxml',
+ SWAN = '.swan',
+ ALIPAY = '.axml',
+ TT = '.ttml',
+ QUICKAPP = '.ux',
+ QQ = '.qml'
+}
+
+export const enum STYLE_TYPES {
+ WEAPP = '.wxss',
+ SWAN = '.css',
+ ALIPAY = '.acss',
+ TT = '.ttss',
+ QUICKAPP = '.css',
+ QQ = '.qss'
+}
+
+export const enum SCRIPT_TYPES {
+ WEAPP = '.js',
+ SWAN = '.js',
+ ALIPAY = '.js',
+ TT = '.js',
+ QUICKAPP = '.js',
+ QQ = '.js'
+}
+
+export const enum CONFIG_TYPES {
+ WEAPP = '.json',
+ SWAN = '.json',
+ ALIPAY = '.json',
+ TT = '.json',
+ QUICKAPP = '.json',
+ QQ = '.json'
+}
+
+export type IMINI_APP_FILE_TYPE = {
+ TEMPL: TEMPLATE_TYPES,
+ STYLE: STYLE_TYPES,
+ SCRIPT: SCRIPT_TYPES,
+ CONFIG: CONFIG_TYPES
+}
+
+export type IMINI_APP_FILES = {
+ [key: string]: IMINI_APP_FILE_TYPE
+}
+export const MINI_APP_FILES: IMINI_APP_FILES = {
+ [BUILD_TYPES.WEAPP]: {
+ TEMPL: TEMPLATE_TYPES.WEAPP,
+ STYLE: STYLE_TYPES.WEAPP,
+ SCRIPT: SCRIPT_TYPES.WEAPP,
+ CONFIG: CONFIG_TYPES.WEAPP
+ },
+ [BUILD_TYPES.SWAN]: {
+ TEMPL: TEMPLATE_TYPES.SWAN,
+ STYLE: STYLE_TYPES.SWAN,
+ SCRIPT: SCRIPT_TYPES.SWAN,
+ CONFIG: CONFIG_TYPES.SWAN
+ },
+ [BUILD_TYPES.ALIPAY]: {
+ TEMPL: TEMPLATE_TYPES.ALIPAY,
+ STYLE: STYLE_TYPES.ALIPAY,
+ SCRIPT: SCRIPT_TYPES.ALIPAY,
+ CONFIG: CONFIG_TYPES.ALIPAY
+ },
+ [BUILD_TYPES.TT]: {
+ TEMPL: TEMPLATE_TYPES.TT,
+ STYLE: STYLE_TYPES.TT,
+ SCRIPT: SCRIPT_TYPES.TT,
+ CONFIG: CONFIG_TYPES.TT
+ },
+ [BUILD_TYPES.QUICKAPP]: {
+ TEMPL: TEMPLATE_TYPES.QUICKAPP,
+ STYLE: STYLE_TYPES.QUICKAPP,
+ SCRIPT: SCRIPT_TYPES.QUICKAPP,
+ CONFIG: CONFIG_TYPES.QUICKAPP
+ },
+ [BUILD_TYPES.QQ]: {
+ TEMPL: TEMPLATE_TYPES.QQ,
+ STYLE: STYLE_TYPES.QQ,
+ SCRIPT: SCRIPT_TYPES.QQ,
+ CONFIG: CONFIG_TYPES.QQ
+ }
+}
+
export const CONFIG_MAP = {
[BUILD_TYPES.WEAPP]: {
navigationBarTitleText: 'navigationBarTitleText',
|
4739713601c5bdd93e59c71d5c7ba53c9db8f286
|
2019-06-03 11:07:17
|
Colder Xihk
|
fix(taro): 增加 getLogManager 类型定义 (#3275)
| false
|
增加 getLogManager 类型定义 (#3275)
|
fix
|
diff --git a/packages/taro/types/index.d.ts b/packages/taro/types/index.d.ts
index 5324275ff779..8ff93fd198ee 100644
--- a/packages/taro/types/index.d.ts
+++ b/packages/taro/types/index.d.ts
@@ -209,7 +209,7 @@ declare namespace Taro {
*
```ts
function expensive () { ... }
-
+
function Component () {
const expensiveResult = useMemo(expensive, [expensive])
return ...
@@ -421,7 +421,7 @@ declare namespace Taro {
* 禁止页面右滑手势返回
* default: false
* @since 微信客户端 7.0.0
- *
+ *
* **注意** 自微信客户端 7.0.5 开始,页面配置中的 disableSwipeBack 属性将不再生效,
* 详情见[右滑手势返回能力调整](https://developers.weixin.qq.com/community/develop/doc/000868190489286620a8b27f156c01)公告
*/
@@ -8623,6 +8623,52 @@ declare namespace Taro {
*/
function getExtConfigSync(): getExtConfigSync.Return
+ namespace getLogManager {
+ type Param = {
+ /**
+ * @since 2.3.2
+ *
+ * 取值为0/1,取值为0表示是否会把 App、Page 的生命周期函数和 wx 命名空间下的函数调用写入日志,取值为1则不会。默认值是 0
+ */
+ level?: number
+ }
+ type Return = {
+ /**
+ * 写 debug 日志
+ */
+ debug(...args: any[]): void
+ /**
+ * 写 info 日志
+ */
+ info(...args: any[]): void
+ /**
+ * 写 log 日志
+ */
+ log(...args: any[]): void
+ /**
+ * 写 warn 日志
+ */
+ warn(...args: any[]): void
+ }
+ }
+ /**
+ * @since 2.1.0
+ *
+ * 获取日志管理器对象。
+ *
+ * **示例代码:**
+ *
+ ```javascript
+ const logger = Taro.getLogManager({level: 1})
+ logger.log({str: 'hello world'}, 'basic log', 100, [1, 2, 3])
+ logger.info({str: 'hello world'}, 'info log', 100, [1, 2, 3])
+ logger.debug({str: 'hello world'}, 'debug log', 100, [1, 2, 3])
+ logger.warn({str: 'hello world'}, 'warn log', 100, [1, 2, 3])
+ ```
+ * @see https://developers.weixin.qq.com/miniprogram/dev/api/base/debug/LogManager.html
+ */
+ function getLogManager(OBJECT?: getLogManager.Param): getLogManager.Return
+
namespace login {
type Promised = {
/**
|
01f53eedf0c68bc97cf9e45ef3751f970a80a170
|
2024-01-15 12:33:55
|
Chen-jj
|
docs(CONTRIBUTING): 更新 CONTRIBUTING.md
| false
|
更新 CONTRIBUTING.md
|
docs
|
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 4225aa335c3f..6ca77940c05a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,138 +2,214 @@
我们非常欢迎社区的开发者向 Taro 做出贡献。在提交贡献之前,请花一些时间阅读以下内容,保证贡献是符合规范并且能帮助到社区。
-## Issue 报告指南
+## 一、Issue 报告指南
-如果提交的是 Bug 报告,请务必遵守 [`Bug report`](https://github.com/NervJS/taro/blob/master/.github/ISSUE_TEMPLATE/bug_report.md) 模板。
+请遵循 [`Taro Issue Template`](https://taro-issue-pro.pf.jd.com/) 的指引创建 Bug Report 或 Feature Request 类 Issues。
-如果提交的是功能需求,请在 issue 的标题的起始处增加 `[Feature request]` 字符。
+## 二、Pull Request 贡献指南
-## 开发配置
+### 1. 环境准备
-> 你需要保证你的 Node.js 版本大于 12
+> 需要安装 [Node.js 16](https://nodejs.org/en/)(建议安装 `16.20.0` 及以上版本)及 [pnpm 7](https://pnpm.io/zh/installation)
-### 安装依赖
+首先把 Taro 仓库 fork 一份到自己的 Github,然后从个人仓库把项目 clone 到本地,项目默认是 `main` 分支。
-基于 pnpm workspace。
+然后依次在项目根目录运行以下命令:
```bash
-$ pnpm install
+# 安装依赖
+$ pnpm i
+# 编译构建
+$ pnpm build
```
-### 编译构建
+运行完上述命令后,环境已经准备好,此时可以新拉一条分支进行开发。
-```bash
-# 全局编译
-$ pnpm run build # 等价于 pnpm -r --filter=./packages/* run build
-
-# 编译某个子包,如 `@tarojs/cli`
-$ pnpm --filter @tarojs/cli run dev
-```
+### 2. 开发与调试
-### 在其他项目中测试
+Taro 由一系列子 npm 包组成,整体项目组织基于 **pnpm workspace**。
-先在 `taro` 项目目录下执行以下命令:
+开发者可以单独修改、编译某个子包:
```bash
-# 编译某个子包,如 `@tarojs/plugin-mini-ci`
-$ pnpm -r --filter ./packages/taro-plugin-mini-ci build
-$ pnpm link --global
+# 编译某个子包,[package-name] 为该子包的 package.json 里的 name 字段
+$ pnpm --filter [package-name] run dev
```
-然后在引用该子包的项目下执行:
-
-```bash
-yarn link @tarojs/plugin-mini-ci
-```
+开发过程中,一般会使用 **link** 的方式把需要调试的包软链到一个测试项目中,然后便可进行断点调试。开发者可以根据测试项目的包管理器以及自己的喜好选择使用 [npm link](https://docs.npmjs.com/cli/v7/commands/npm-link) 或 [yarn link](https://yarnpkg.com/cli/link)(推荐)或 [pnpm link](https://pnpm.io/zh/cli/link) 。
-接着,就可以在引用该子包的项目中从本地使用该子包了。在测试完毕后,可以执行以下命令取消链接:
+**使用 `yarn link` 的具体示例如下:**
-```bash
-yarn unlink @tarojs/plugin-mini-ci
-```
+1. 进入需要调试的子包的根目录,然后执行 `yarn link`。
+2. 进入测试项目的根目录,然后执行 `yarn link`。(注意被调试的子包的版本要和测试项目中该依赖的版本保持一致)
-### 新增/删除依赖
+**使用 `pnpm link` 的具体示例如下:**
-可以分为三种情况:
+情况一、测试项目 `package.json` 中有声明对该包的依赖
-> 应该尽量把子包的 devDependencies 作为根目录的 devDependencies,从而安装在根目录。
-> 如果版本遇到冲突,可以安装在子包内。
+1. 进入需要调试的子包的根目录,然后执行 `pnpm link --global`。
+2. 进入测试项目的根目录,然后执行 `pnpm link --global [package-name]`。
-#### 1. 根目录
+情况二、测试项目 `package.json` 中没有声明对该包的依赖,该依赖包是被某个 Taro 包间接依赖的,如 `@tarojs/runner-utils`。
-```bash
-# 新增
-$ pnpm add -wD <dependency>
+1. 测试项目的 `package.json` 中新增 pnpm 配置并配置该依赖包的具体链接路径
-# 删除
-$ pnpm remove -wD <dependency>
+```json
+"pnpm": {
+ "overrides": {
+ "@tarojs/runner-utils": "/Users/.../taro/packages/taro-runner-utils"
+ }
+},
+```
+2. 执行 `pnpm i` 重新安装测试项目的依赖
+
+在测试项目中创建好链接后,接下来就可以启动项目编译。注意如果是编译 H5 或小程序时,请提前关闭依赖预编译配置:
+
+```json
+// /demo/config/dev.js
+compiler: {
+ type: "webpack5",
+ prebundle: {
+ enable: false,
+ }
+}
```
-#### 2. 操作某个子包
+接下来在需要被调试的包中加入断点,**运行时代码**可以在各端的开发工具(小程序开发者工具、Chrome...)中断点调试,而**编译时**的代码需要使用 VSCode debugger 进行断点调试,请参考 Taro 文档中《单步调测》章节。
+
+> 以上是通用的开发/调试步骤,部分子包可能会有额外需要注意的地方,开发前请查阅对应子包的 README。
+
+### 3. 新增/删除依赖
+
+推荐遵循的依赖治理规范:
+
+- 尽量把子包用到的 `dependencies` 和 `devDependencies` 安装在子包。
+- TypeScript、各种 Lint 工具、Rollup 等用于治理 Taro 项目的依赖推荐安装在主包。
+- 如果子包是插件类项目,使用 `peerDependencies` 声明实际项目中肯定会安装的依赖。
```bash
+# 在根目录新增依赖
+$ pnpm add -wD <dependency>
+# 在根目录删除依赖
+$ pnpm remove -wD <dependency>
# 为某个子包(如 @tarojs/cli)新增一个依赖
$ pnpm --filter @tarojs/cli add <dependency>
-
# 为某个子包(如 @tarojs/cli)删除一个依赖
$ pnpm --filter @tarojs/cli remove <dependency>
+# 为所有子包新增一个依赖
+$ pnpm -r --filter=./packages/* add <dependency>
+# 为所有子包删除一个依赖
+$ pnpm -r --filter=./packages/* remove <dependency>
+# 删除根目录的 node_modules 和所有 workspace 里的 node_modules
+$ npm run clear-all
```
-#### 3. 操作所有子包
+### 4. 单元测试
-```bash
-# 新增
-$ pnpm -r --filter=./packages/* add <dependency>
+`package.json` 中设置了 `test:ci` 命令的子包都配备了单元测试。
-# 删除
-$ pnpm -r --filter=./packages/* remove <dependency>
-```
+开发者在修改这些包后,请运行 `pnpm --filter [package-name] run test:ci`,检查测试用例是否都能通过。
+
+同时,在开发一些重要功能后,也请抽时间补上对应的测试用例。
+
+**注意:**
+
+`@tarojs/mini-runner`、`@tarojs/webpack-runner`、`@tarojs/webpack5-runner` 使用了 `snapshot`(测试结果快照)。在修改这两个包或其它一些包时,有可能导致这些快照失效,从而通过不了测试。当你修改了这两个包、或 Github CI 提示这些包的测试用例出错时,请运行 `pnpm --filter [package-name] runupdateSnapshot` 更新 snapshot 后重新提交。
+
+### 5. 代码风格
+
+* `JavaScript`:JavaScript 风格遵从 [JavaScript Standard Style](https://github.com/standard/standard)。
+* `TypeScript`:TypeScript 风格也是 [JavaScript Standard Style](https://github.com/standard/standard) 的变种,详情请看相关包目录下的 `eslint.json` 和 `tsconfig.json`。
+* 样式:遵循相关包目录下的 `.stylelintrc` 风格。
+
+### 6. 提交 commit
+
+整个 Taro 仓库遵从 [Angular Style Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153),在输入 commit message 的时候请务必遵从此规范。
+
+### 7. 提交 Pull Request
+
+> 如果对 PR(Pull Request)不了解,请阅读 [《About Pull Requests》](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)
+
+完成开发后,推送到自己的 Taro 仓库,就可以准备提交 Pull Request 了。
-### 清理所有依赖
+提交 PR 前请阅读以下注意事项:
+
+1. 保证 `npm run build` 能够编译成功。
+2. 保证代码能通过 ESLint 测试。
+3. 当相关包含有 `npm test:ci` 命令时,必须保证所有测试用例都能够通过;
+4. 当相关包有测试用例时,请给你提交的代码也添加相应的测试用例;
+5. 保证 commit 信息需要遵循 [Angular Style Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153)。
+6. 如果提交到代码非常多或功能复杂,可以把 PR 分成几个 commit 一起提交。我们在合并时会会根据情况 squash。
+7. PR 作者可以选择加入到 Taro 开发者微信群,方便合并 PR 和技术交流。
+
+### 8. 发布测试版本
+
+提交 PR 后,开发者可以在开发分支上发布测试版本到 npm。部分难以在本地验证的功能可以使用这种方式进行验证。
+
+1. 确保分支名以 `feat/` 或 `chore/` 开头。
+2. 在 Taro 项目根目录执行命令:
```bash
-# 包括删除根目录的 node_modules 和所有 workspace 里的 node_modules
-$ npm run clear-all
+# 更新 workspace 内所有子包的版本号,如 pnpm version 3.6.22-alpha.0
+$ pnpm version <version>
```
-### 运行子包的 `npm script`
+3. 执行 `git commit --amend` 命令,手动修改最新一个 commit 的 commit message,加上 `--tag=<tag>`(此 tag 代表发布的 npm tag)。如发布 alpha 版本:`chore(release): publish 3.6.22-alpha.0 --tag=alpha`。
+4. 提交修改到远程仓库,将会触发 Github CI 的发布流程。
+
+### 9. 文档
+
+当提交涉及新增特性、Breaking Changes 或重要修改时,请及时新增、修改对应的文档。
+
+关于文档的开发请阅读下一章节:《贡献文档》。
+
+### 10. Rust 部分
+
+Taro 仓库里有部分使用 Rust 开发的子包,在开发、调试、测试这些包时有不一样的流程。
+
+Rust 代码存放在 `crates` 文件夹下,使用 Cargo workspace 管理,目前包括 NAPI bindings 和若干 SWC 插件。
+
+开发前请使用 `rustup` 安装 Rust 工具链。
+
+#### NAPI bindings
+
+在根目录执行 `pnpm build:binding:debug` 或 `pnpm build:binding:release` 命令,会在 `crates/native-binding` 文件夹中编译出 binding 文件 `taro.[os-platform].node`。
+
+然后可以执行单元测试:
```bash
-$ pnpm --filter <workspace> run <script-name>
+$ pnpm --filter @tarojs/binding run test
```
-### 提交发布
-
-- PR 发布规则
+或结合调用方执行集成测试。
- ```bash
- $ pnpm version <version>
- ```
+#### SWC 插件
-- `feat/**` 分支发布规则
+首先在项目根目录执行 `rustup target add wasm32-wasi` 命令安装 `wasm32-wasi` 的 `target`。
- ```bash
- $ pnpm version <version> --tag=<tag>
- ```
+开发过程中可以使用 SWC 测试套件进行单元测试:
-## 提交 commit
+```bash
+# 执行所有 SWC 插件的单元测试
+$ cargo test-swc-plugins
+# 执行某个 SWC 插件的单元测试
+$ cargo test -p [package-name]
+```
-整个 Taro 仓库遵从 [Angular Style Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153),在输入 commit message 的时候请务必遵从此规范。
+功能完成后可以编译出 `.wasm` 文件,联合调用方进行集成测试:
-## 代码风格
+```bash
+# 编译所有 SWC 插件
+$ cargo build-swc-plugins
+# 编译某个 SWC 插件
+$ cargo build -p [package-name]
+```
-* `JavaScript`:JavaScript 风格遵从 [JavaScript Standard Style](https://github.com/standard/standard)。
-* `TypeScript`:TypeScript 风格也是 [JavaScript Standard Style](https://github.com/standard/standard) 的变种,详情请看相关包目录下的 `eslint.json` 和 `tsconfig.json`。
-* 样式:遵循相关包目录下的 `.stylelintrc` 风格。
+Cargo workspace 会把编译产物输出到根目录的 `target` 文件夹中。进行集成测试时,需要手动把 `.wasm` 产物软链到目标文件夹,而 Github CI 在正式发布时会自动拷贝产物到正确的文件夹中。
-## Pull Request 指南
+如对 `@taorjs/helper` 进行集成测试时,会把 `target/wasm32-wasi/release/swc_plugin_xxx.wasm` 文件的软链到 `packages/taro-helper/swc/swc_plugin_xxx.wasm`。
-1. 务必保证 `npm run build` 能够编译成功;
-2. 务必保证提交的代码遵循相关包中的 `.eslintrc`, `.tslintrc`, `.stylelintrc` 所规定的规范;
-3. 当相关包的 `package.json` 含有 `npm test` 命令时,必须保证所有测试用例都需要通过;
-4. 当相关包有测试用例时,请给你提交的代码也添加相应的测试用例。
-5. 提交代码 commit 时,commit 信息需要遵循 [Angular Style Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153)。
-6. 如果提交的代码非常多或功能复杂,可以把 PR 分成几个 commit 一起提交。我们在合并时会根据情况 squash。
+####
## Credits
|
a4858b78f0a05aed91b98c92000b1fefc03cce18
|
2020-09-25 08:35:00
|
ZakaryCode
|
fix(test): add timeout
| false
|
add timeout
|
fix
|
diff --git a/packages/taro-components/__tests__/polyfill.js b/packages/taro-components/__tests__/polyfill.js
index a467cc0c2987..3a42e6f006b3 100644
--- a/packages/taro-components/__tests__/polyfill.js
+++ b/packages/taro-components/__tests__/polyfill.js
@@ -1,7 +1,7 @@
import { applyPolyfills, defineCustomElements } from '../loader/index.es2017.mjs'
import '../dist/taro-components/taro-components.css'
-jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
+jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000
// 此文件只要 import 一次即可
applyPolyfills().then(() => {
diff --git a/packages/taro-components/__tests__/scroll-view.spec.js b/packages/taro-components/__tests__/scroll-view.spec.js
index 7a4e4fbee2a7..f61c4df3a3b4 100644
--- a/packages/taro-components/__tests__/scroll-view.spec.js
+++ b/packages/taro-components/__tests__/scroll-view.spec.js
@@ -17,7 +17,7 @@ describe('ScrollView', () => {
beforeAll(() => {
originTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
- jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000
+ jasmine.DEFAULT_TIMEOUT_INTERVAL = 40000
})
beforeEach(() => {
|
db8e267b7f2c80e788ea11c3908d7681179603b0
|
2018-07-25 08:58:51
|
luckyadam
|
feat(cli): 小程序端编译增加 CSS 中引用本地资源替换成 base64 功能
| false
|
小程序端编译增加 CSS 中引用本地资源替换成 base64 功能
|
feat
|
diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json
index 7bbe180464b4..08cb110b8657 100644
--- a/packages/taro-cli/package.json
+++ b/packages/taro-cli/package.json
@@ -48,6 +48,7 @@
"ora": "^2.0.0",
"postcss": "^6.0.22",
"postcss-pxtransform": "0.0.72",
+ "postcss-url": "^7.3.2",
"resolve": "^1.6.0",
"semver": "^5.5.0",
"shelljs": "^0.8.1",
diff --git a/packages/taro-cli/src/weapp.js b/packages/taro-cli/src/weapp.js
index affb7fa71800..2339d6216027 100644
--- a/packages/taro-cli/src/weapp.js
+++ b/packages/taro-cli/src/weapp.js
@@ -11,6 +11,7 @@ const template = require('babel-template')
const autoprefixer = require('autoprefixer')
const postcss = require('postcss')
const pxtransform = require('postcss-pxtransform')
+const cssUrlParse = require('postcss-url')
const minimatch = require('minimatch')
const _ = require('lodash')
@@ -781,6 +782,42 @@ async function buildSinglePage (page) {
}
}
+async function processStyleWithPostCSS (styleObj) {
+ const weappConf = projectConfig.weapp || {}
+ const useModuleConf = weappConf.module || {}
+ const customPostcssConf = useModuleConf.postcss || {}
+ const customPxtransformConf = customPostcssConf.pxtransform || {}
+ const postcssPxtransformOption = {
+ designWidth: projectConfig.designWidth || 750,
+ platform: 'weapp'
+ }
+
+ const DEVICE_RATIO = 'deviceRatio'
+ if (projectConfig.hasOwnProperty(DEVICE_RATIO)) {
+ postcssPxtransformOption[DEVICE_RATIO] = projectConfig.deviceRatio
+ }
+ const cssUrlConf = Object.assign({ limit: 10240, enable: true }, weappConf.cssUrl)
+ const maxSize = Math.round(cssUrlConf.limit / 1024)
+ const processors = [
+ autoprefixer({ browsers: browserList }),
+ pxtransform(Object.assign(
+ postcssPxtransformOption,
+ customPxtransformConf
+ ))
+ ]
+ if (cssUrlConf.enable) {
+ processors.push(cssUrlParse({
+ url: 'inline',
+ maxSize,
+ encodeType: 'base64'
+ }))
+ }
+ const postcssResult = await postcss(processors).process(styleObj.css, {
+ from: styleObj.filePath
+ })
+ return postcssResult.css
+}
+
function compileDepStyles (outputFilePath, styleFiles, depStyleList) {
if (isBuildingStyles[outputFilePath]) {
return Promise.resolve({})
@@ -792,6 +829,10 @@ function compileDepStyles (outputFilePath, styleFiles, depStyleList) {
const pluginName = Util.FILE_PROCESSOR_MAP[fileExt]
if (pluginName) {
return npmProcess.callPlugin(pluginName, null, filePath, pluginsConfig[pluginName] || {})
+ .then(res => ({
+ css: res.css,
+ filePath
+ }))
}
return new Promise((resolve, reject) => {
fs.readFile(filePath, (err, content) => {
@@ -799,57 +840,32 @@ function compileDepStyles (outputFilePath, styleFiles, depStyleList) {
return reject(err)
}
resolve({
- css: content
+ css: content,
+ filePath
})
})
})
})).then(async resList => {
- let resContent = resList.map(res => res.css).join('\n')
- const weappConf = projectConfig.weapp || {}
- const useModuleConf = weappConf.module || {}
- const customPostcssConf = useModuleConf.postcss || {}
- const customPxtransformConf = customPostcssConf.pxtransform || {}
-
- try {
- const postcssPxtransformOption = {
- designWidth: projectConfig.designWidth || 750,
- platform: 'weapp'
- }
-
- const DEVICE_RATIO = 'deviceRatio'
- if (projectConfig.hasOwnProperty(DEVICE_RATIO)) {
- postcssPxtransformOption[DEVICE_RATIO] = projectConfig.deviceRatio
- }
-
- const postcssResult = await postcss([
- autoprefixer({ browsers: browserList }),
- pxtransform(Object.assign(
- postcssPxtransformOption,
- customPxtransformConf
- ))
- ]).process(resContent, {
- from: undefined
- })
- resContent = postcssResult.css
- if (depStyleList && depStyleList.length) {
- const importStyles = depStyleList.map(item => {
- return `@import "${item}";\n`
- }).join('')
- resContent = importStyles + resContent
- }
- if (isProduction) {
- const cssoPuginConfig = pluginsConfig.csso || { enable: true }
- if (cssoPuginConfig.enable) {
- const cssoConfig = cssoPuginConfig.config || {}
- const cssoResult = npmProcess.callPluginSync('csso', resContent, outputFilePath, cssoConfig)
- resContent = cssoResult.css
+ Promise.all(resList.map(res => processStyleWithPostCSS(res)))
+ .then(cssList => {
+ let resContent = cssList.map(res => res).join('\n')
+ if (depStyleList && depStyleList.length) {
+ const importStyles = depStyleList.map(item => {
+ return `@import "${item}";\n`
+ }).join('')
+ resContent = importStyles + resContent
}
- }
- fs.ensureDirSync(path.dirname(outputFilePath))
- fs.writeFileSync(outputFilePath, resContent)
- } catch (err) {
- console.log(err)
- }
+ if (isProduction) {
+ const cssoPuginConfig = pluginsConfig.csso || { enable: true }
+ if (cssoPuginConfig.enable) {
+ const cssoConfig = cssoPuginConfig.config || {}
+ const cssoResult = npmProcess.callPluginSync('csso', resContent, outputFilePath, cssoConfig)
+ resContent = cssoResult.css
+ }
+ }
+ fs.ensureDirSync(path.dirname(outputFilePath))
+ fs.writeFileSync(outputFilePath, resContent)
+ })
})
}
diff --git a/packages/taro-cli/templates/default/config/index b/packages/taro-cli/templates/default/config/index
index 0787c8074b96..e093b0c69c4a 100644
--- a/packages/taro-cli/templates/default/config/index
+++ b/packages/taro-cli/templates/default/config/index
@@ -59,7 +59,10 @@ const config = {
}
},
weapp: {
-
+ cssUrl: {
+ limit: 10240,
+ enable: true
+ }
},
h5: {
publicPath: '/',
diff --git a/packages/taro-cli/yarn.lock b/packages/taro-cli/yarn.lock
index 0ecb21da080c..cbbaede391db 100644
--- a/packages/taro-cli/yarn.lock
+++ b/packages/taro-cli/yarn.lock
@@ -733,6 +733,10 @@ css@^2.2.1:
source-map-resolve "^0.5.1"
urix "^0.1.0"
+cuint@^0.2.2:
+ version "0.2.2"
+ resolved "https://registry.npmjs.org/cuint/-/cuint-0.2.2.tgz#408086d409550c2631155619e9fa7bcadc3b991b"
+
debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
@@ -1640,6 +1644,10 @@ micromatch@^3.1.10, micromatch@^3.1.4:
snapdragon "^0.8.1"
to-regex "^3.0.2"
+mime@^1.4.1:
+ version "1.6.0"
+ resolved "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
+
mimic-fn@^1.0.0:
version "1.2.0"
resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
@@ -1989,6 +1997,16 @@ [email protected]:
postcss "^6.0.16"
postcss-pxtorem "^4.0.1"
+postcss-url@^7.3.2:
+ version "7.3.2"
+ resolved "https://registry.npmjs.org/postcss-url/-/postcss-url-7.3.2.tgz#5fea273807fb84b38c461c3c9a9e8abd235f7120"
+ dependencies:
+ mime "^1.4.1"
+ minimatch "^3.0.4"
+ mkdirp "^0.5.0"
+ postcss "^6.0.1"
+ xxhashjs "^0.2.1"
+
postcss-value-parser@^3.2.3, postcss-value-parser@^3.3.0:
version "3.3.0"
resolved "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-3.3.0.tgz#87f38f9f18f774a4ab4c8a232f5c5ce8872a9d15"
@@ -2002,7 +2020,7 @@ postcss@^5.2.10:
source-map "^0.5.6"
supports-color "^3.2.3"
-postcss@^6.0.16, postcss@^6.0.22:
+postcss@^6.0.1, postcss@^6.0.16, postcss@^6.0.22:
version "6.0.23"
resolved "https://registry.npmjs.org/postcss/-/postcss-6.0.23.tgz#61c82cc328ac60e677645f979054eb98bc0e3324"
dependencies:
@@ -2691,6 +2709,12 @@ xtend@~4.0.0, xtend@~4.0.1:
version "4.0.1"
resolved "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
+xxhashjs@^0.2.1:
+ version "0.2.2"
+ resolved "https://registry.npmjs.org/xxhashjs/-/xxhashjs-0.2.2.tgz#8a6251567621a1c46a5ae204da0249c7f8caa9d8"
+ dependencies:
+ cuint "^0.2.2"
+
yallist@^3.0.0, yallist@^3.0.2:
version "3.0.2"
resolved "https://registry.npmjs.org/yallist/-/yallist-3.0.2.tgz#8452b4bb7e83c7c188d8041c1a837c773d6d8bb9"
|
43388fd2c2eacde456b5afc8eac25d8b27d8d061
|
2023-01-17 16:33:57
|
bigMeow
|
perf: 优化代码
| false
|
优化代码
|
perf
|
diff --git a/packages/taro-plugin-http/src/runtime/Cookie.ts b/packages/taro-plugin-http/src/runtime/Cookie.ts
index f429566fd945..6ed87ee46468 100644
--- a/packages/taro-plugin-http/src/runtime/Cookie.ts
+++ b/packages/taro-plugin-http/src/runtime/Cookie.ts
@@ -1,3 +1,5 @@
+// Copyright (c) 2019 wechat-miniprogram MIT License
+// Reference and modify code by miniprogram-render/src/bom/cookie.js
import { parseUrl } from '@tarojs/runtime'
import { getStorageSync, setStorage } from '@tarojs/taro'
@@ -295,5 +297,3 @@ export function createCookieInstance () {
}
return cookieInstance
}
-
-// 特别感谢: 此 Cookie 实现参考自 `https://github.com/Tencent/kbone`
diff --git a/packages/taro-runtime/src/dom/anchor-element.ts b/packages/taro-runtime/src/dom/anchor-element.ts
new file mode 100644
index 000000000000..2e6de35f0291
--- /dev/null
+++ b/packages/taro-runtime/src/dom/anchor-element.ts
@@ -0,0 +1,63 @@
+import { parseUrl } from '../bom/location'
+import { TaroElement } from './element'
+
+const enum AnchorElementAttrs {
+ HREF = 'href',
+ PROTOCOL = 'protocol',
+ HOST = 'host',
+ SEARCH = 'search',
+ HASH = 'hash',
+ HOSTNAME = 'hostname',
+ PORT = 'port',
+ PATHNAME = 'pathname'
+}
+
+export class AnchorElement extends TaroElement {
+ public get href () {
+ return this.props[AnchorElementAttrs.HREF] ?? ''
+ }
+
+ public set href (val: string) {
+ this.setAttribute(AnchorElementAttrs.HREF, val)
+ }
+
+ get protocol () {
+ return this.props[AnchorElementAttrs.PROTOCOL] ?? ''
+ }
+
+ get host () {
+ return this.props[AnchorElementAttrs.HOST] ?? ''
+ }
+
+ get search () {
+ return this.props[AnchorElementAttrs.SEARCH] ?? ''
+ }
+
+ get hash () {
+ return this.props[AnchorElementAttrs.HASH] ?? ''
+ }
+
+ get hostname () {
+ return this.props[AnchorElementAttrs.HOSTNAME] ?? ''
+ }
+
+ get port () {
+ return this.props[AnchorElementAttrs.PORT] ?? ''
+ }
+
+ get pathname () {
+ return this.props[AnchorElementAttrs.PATHNAME] ?? ''
+ }
+
+ public setAttribute (qualifiedName: string, value: any): void {
+ if (qualifiedName === AnchorElementAttrs.HREF) {
+ const willSetAttr = parseUrl(value)
+ for (const k in willSetAttr) {
+ super.setAttribute(k, willSetAttr[k])
+ }
+ } else {
+ super.setAttribute(qualifiedName, value)
+ }
+ }
+
+}
diff --git a/packages/taro-runtime/src/dom/anchorElement.ts b/packages/taro-runtime/src/dom/anchorElement.ts
deleted file mode 100644
index e5a34b183044..000000000000
--- a/packages/taro-runtime/src/dom/anchorElement.ts
+++ /dev/null
@@ -1,73 +0,0 @@
-import { parseUrl } from '../bom/location'
-import { TaroElement } from './element'
-
-const enum AnchorElementAttrs {
- HREF = 'href',
- PROTOCOL = 'protocol',
- HOST = 'host',
- SEARCH = 'search',
- HASH ='hash',
- HOSTNAME = 'hostname',
- PORT = 'port',
- PATHNAME= 'pathname'
-}
-
-export class AnchorElement extends TaroElement {
- public get href () {
- // eslint-disable-next-line dot-notation
- const href = this.props[AnchorElementAttrs.HREF]
- return href == null ? '' : href
- }
-
- public set href (val: string) {
- this.setAttribute(AnchorElementAttrs.HREF, val)
- }
-
- get protocol () {
- const v = this.props[AnchorElementAttrs.PROTOCOL]
- return v == null ? '' : v
- }
-
- get host () {
- const v = this.props[AnchorElementAttrs.HOST]
- return v == null ? '' : v
- }
-
- get search () {
- const v = this.props[AnchorElementAttrs.SEARCH]
- return v == null ? '' : v
- }
-
- get hash () {
- const v = this.props[AnchorElementAttrs.HASH]
- return v == null ? '' : v
- }
-
- get hostname () {
- const v = this.props[AnchorElementAttrs.HOSTNAME]
- return v == null ? '' : v
- }
-
- get port () {
- const v = this.props[AnchorElementAttrs.PORT]
- return v == null ? '' : v
- }
-
- get pathname () {
- const v = this.props[AnchorElementAttrs.PATHNAME]
- return v == null ? '' : v
- }
-
- public setAttribute (qualifiedName: string, value: any): void {
- if (qualifiedName === AnchorElementAttrs.HREF) {
- const willSetAttr = parseUrl(value)
- for (const k in willSetAttr) {
- super.setAttribute(k, willSetAttr[k])
- }
- } else {
- super.setAttribute(qualifiedName, value)
- }
- }
-
-}
-
\ No newline at end of file
diff --git a/packages/taro-runtime/src/dom/document.ts b/packages/taro-runtime/src/dom/document.ts
index 6c492d392169..0c5f4ee97a39 100644
--- a/packages/taro-runtime/src/dom/document.ts
+++ b/packages/taro-runtime/src/dom/document.ts
@@ -14,7 +14,7 @@ import { NodeType } from '../dom/node_types'
import { TaroRootElement } from '../dom/root'
import { TaroText } from '../dom/text'
import env from '../env'
-import { AnchorElement } from './anchorElement'
+import { AnchorElement } from './anchor-element'
export class TaroDocument extends TaroElement {
public documentElement: TaroElement
|
3b06709e0b115ab9b9a838b54a289675b3b67c02
|
2022-04-24 14:53:45
|
Zakary
|
fix(types): webpack deps
| false
|
webpack deps
|
fix
|
diff --git a/package.json b/package.json
index 5d31ad1291c8..f55edc5b7a97 100644
--- a/package.json
+++ b/package.json
@@ -89,6 +89,8 @@
"@types/sinon": "^7.5.0",
"@types/tapable": "^1",
"@types/testing-library__jest-dom": "^5.14.3",
+ "@types/webpack": "4",
+ "@types/webpack-dev-server": "3",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"@vue/compiler-core": "3.0.0",
@@ -160,7 +162,9 @@
"typescript": "4.3.5",
"vue": "^2.6.11",
"vue-loader": "^15.9.3",
- "vue-template-compiler": "^2.6.11"
+ "vue-template-compiler": "^2.6.11",
+ "webpack": "4.46.0",
+ "webpack-dev-server": "3.11.3"
},
"version": "3.4.2"
}
diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json
index 5bddcd1bdbb5..8a45919dc813 100644
--- a/packages/taro-components-rn/package.json
+++ b/packages/taro-components-rn/package.json
@@ -4,7 +4,7 @@
"description": "多端解决方案基础组件(RN)",
"main": "./dist/index.js",
"scripts": {
- "assets": "cpy \"**/*.png\" \"../dist/\" --cwd=src --parents",
+ "assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist",
"build": "rimraf ./dist && tsc && yarn assets",
"dev": "yarn assets && tsc --watch",
"lint": "eslint .",
diff --git a/packages/taro-components-rn/tsconfig.json b/packages/taro-components-rn/tsconfig.json
index c8991a7aa1e5..879f636e617a 100644
--- a/packages/taro-components-rn/tsconfig.json
+++ b/packages/taro-components-rn/tsconfig.json
@@ -8,11 +8,11 @@
"esModuleInterop": true,
"jsx": "react",
"paths": {
- "react": ["./node_modules/@types/react"]
+ "react": ["./node_modules/@types/react", "./node_modules/react"],
},
"types": ["react-native", "jest"],
- "typeRoots": ["./node_modules/@types", "../../node_modules/@types"]
+ "typeRoots": ["./node_modules/@types", "../../node_modules/@types"],
},
"include": ["./src"],
- "exclude": ["./src/__tests__/**"]
+ "exclude": ["./src/__tests__/**"],
}
diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json
index 7d1671e01672..9cc162164559 100644
--- a/packages/taro-h5/package.json
+++ b/packages/taro-h5/package.json
@@ -14,9 +14,9 @@
],
"sideEffects": false,
"scripts": {
- "copy:assets": "cpy src/**/*.css dist",
- "build": "tsc && npm run copy:assets && rollup -c",
- "predev": "npm run copy:assets",
+ "assets": "cpy 'src/**/*.css' dist",
+ "build": "rimraf ./dist && tsc && npm run assets && rollup -c",
+ "predev": "npm run assets",
"dev": "tsc -w",
"test": "jest",
"test:ci": "jest -i --coverage false",
diff --git a/packages/taro-mini-runner/package.json b/packages/taro-mini-runner/package.json
index 3fe28a88a6f6..db5c1b53b32f 100644
--- a/packages/taro-mini-runner/package.json
+++ b/packages/taro-mini-runner/package.json
@@ -90,5 +90,8 @@
"webpack": "4.46.0",
"webpack-chain": "4.9.0",
"webpack-format-messages": "^2.0.5"
+ },
+ "devDependencies": {
+ "@types/webpack": "4"
}
}
diff --git a/packages/taro-mini-runner/tsconfig.json b/packages/taro-mini-runner/tsconfig.json
index 60b641fdc896..eff9d9d5fc17 100644
--- a/packages/taro-mini-runner/tsconfig.json
+++ b/packages/taro-mini-runner/tsconfig.json
@@ -8,15 +8,17 @@
"module": "commonjs",
"sourceMap": true,
"preserveConstEnums": true,
+ "paths": {
+ "webpack": ["./node_modules/@types/webpack", "./node_modules/webpack"],
+ "webpack-dev-server": ["./types/slim.d.ts"],
+ },
"skipLibCheck": true
},
- "include": [
- "./src"
- ],
+ "include": ["./src", "./types"],
"exclude": [
"./src/__tests__",
"./src/template/comp.ts",
"./src/quickapp",
- "./src/loaders/quickappStyleLoader.ts"
- ]
+ "./src/loaders/quickappStyleLoader.ts",
+ ],
}
diff --git a/packages/taro-mini-runner/types/slim.d.ts b/packages/taro-mini-runner/types/slim.d.ts
new file mode 100644
index 000000000000..e5eab33718f6
--- /dev/null
+++ b/packages/taro-mini-runner/types/slim.d.ts
@@ -0,0 +1 @@
+// Skip typing this file to skip errors in the above type definition.
diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json
index 2a9e794f3050..7da587341143 100644
--- a/packages/taro-rn/package.json
+++ b/packages/taro-rn/package.json
@@ -12,7 +12,7 @@
"libList.js"
],
"scripts": {
- "assets": "cpy \"**/*.png\" \"../dist/\" --cwd=src --parents",
+ "assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist",
"build": "rimraf ./dist && tsc && yarn assets && yarn script",
"dev": "yarn assets && tsc --watch",
"lint": "eslint .",
diff --git a/packages/taro-rn/tsconfig.json b/packages/taro-rn/tsconfig.json
index 0e5d41be27b7..a64701dc27e8 100644
--- a/packages/taro-rn/tsconfig.json
+++ b/packages/taro-rn/tsconfig.json
@@ -8,11 +8,11 @@
"jsx": "react",
"lib": ["ESNEXT"],
"paths": {
- "react": ["./node_modules/@types/react"],
- "vue": ["./src/types/vue/index.d.ts"]
+ "react": ["./node_modules/@types/react", "./node_modules/react"],
+ "vue": ["./src/types/vue/index.d.ts"],
},
- "typeRoots": ["./node_modules/@types"]
+ "typeRoots": ["./node_modules/@types"],
},
"include": ["./src", "./types"],
- "exclude": ["./src/__tests__/**"]
+ "exclude": ["./src/__tests__/**"],
}
diff --git a/packages/taro-router-rn/tsconfig.json b/packages/taro-router-rn/tsconfig.json
index 784024d2030d..7254e60119f2 100644
--- a/packages/taro-router-rn/tsconfig.json
+++ b/packages/taro-router-rn/tsconfig.json
@@ -7,9 +7,9 @@
"jsx": "react",
"lib": ["ESNEXT"],
"paths": {
- "react": ["./node_modules/@types/react"]
+ "react": ["./node_modules/@types/react", "./node_modules/react"],
},
- "types": ["react-native", "node"]
+ "types": ["react-native", "node"],
},
- "include": ["src"]
+ "include": ["src"],
}
diff --git a/packages/taro-runtime-rn/tsconfig.json b/packages/taro-runtime-rn/tsconfig.json
index c3ad403d8709..6640f4819a36 100644
--- a/packages/taro-runtime-rn/tsconfig.json
+++ b/packages/taro-runtime-rn/tsconfig.json
@@ -7,9 +7,9 @@
"jsx": "react",
"lib": ["ESNEXT"],
"paths": {
- "react": ["./node_modules/@types/react"]
+ "react": ["./node_modules/@types/react", "./node_modules/react"],
},
- "types": ["react-native", "node"]
+ "types": ["react-native", "node"],
},
- "include": ["./src"]
+ "include": ["./src"],
}
diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json
index 4991d218a87c..b2ed71f4fd6e 100644
--- a/packages/taro-webpack-runner/package.json
+++ b/packages/taro-webpack-runner/package.json
@@ -68,6 +68,7 @@
"webpack-format-messages": "^2.0.5"
},
"devDependencies": {
+ "@types/webpack": "4",
"@types/webpack-dev-server": "3"
}
}
diff --git a/packages/taro-webpack-runner/src/index.ts b/packages/taro-webpack-runner/src/index.ts
index d3c55cd2d1b6..4355aae031db 100644
--- a/packages/taro-webpack-runner/src/index.ts
+++ b/packages/taro-webpack-runner/src/index.ts
@@ -1,9 +1,9 @@
+import { recursiveMerge } from '@tarojs/helper'
import * as detectPort from 'detect-port'
import * as path from 'path'
import { format as formatUrl } from 'url'
import * as webpack from 'webpack'
import * as WebpackDevServer from 'webpack-dev-server'
-import { recursiveMerge } from '@tarojs/helper'
import buildConf from './config/build.conf'
import devConf from './config/dev.conf'
@@ -13,7 +13,6 @@ import { addLeadingSlash, addTrailingSlash, formatOpenHost } from './util'
import { bindDevLogger, bindProdLogger, printBuildError } from './util/logHelper'
import { BuildConfig, Func } from './util/types'
import { makeConfig } from './util/chain'
-import type { Compiler } from 'webpack'
export const customizeChain = async (chain, modifyWebpackChainFunc: Func, customizeFunc?: Func) => {
if (modifyWebpackChainFunc instanceof Function) {
@@ -73,7 +72,7 @@ const buildDev = async (appPath: string, config: BuildConfig): Promise<any> => {
const routerBasename = routerConfig.basename || '/'
const publicPath = conf.publicPath ? addLeadingSlash(addTrailingSlash(conf.publicPath)) : '/'
const outputPath = path.join(appPath, conf.outputRoot as string)
- const customDevServerOption = config.devServer || {}
+ const customDevServerOption = (config.devServer || {}) as WebpackDevServer.Configuration
const webpackChain = devConf(appPath, config)
const onBuildFinish = config.onBuildFinish
await customizeChain(webpackChain, config.modifyWebpackChain, config.webpackChain)
@@ -129,7 +128,7 @@ const buildDev = async (appPath: string, config: BuildConfig): Promise<any> => {
const webpackConfig = webpackChain.toConfig()
WebpackDevServer.addDevServerEntrypoints(webpackConfig, devServerOptions)
- const compiler = webpack(webpackConfig) as Compiler
+ const compiler = webpack(webpackConfig) as webpack.Compiler
bindDevLogger(devUrl, compiler)
const server = new WebpackDevServer(compiler, devServerOptions)
compiler.hooks.emit.tapAsync('taroBuildDone', async (compilation, callback) => {
diff --git a/packages/taro-webpack-runner/tsconfig.json b/packages/taro-webpack-runner/tsconfig.json
index 5a3f11851c5a..f0c6c1386192 100644
--- a/packages/taro-webpack-runner/tsconfig.json
+++ b/packages/taro-webpack-runner/tsconfig.json
@@ -7,12 +7,12 @@
"module": "commonjs",
"sourceMap": true,
"paths": {
- "webpack": ["./node_modules/webpack"],
- "webpack-dev-server": ["./node_modules/@types/webpack-dev-server"],
+ "webpack": ["./node_modules/@types/webpack", "./node_modules/webpack"],
+ "webpack-dev-server": ["./node_modules/@types/webpack-dev-server", "./node_modules/webpack-dev-server"],
},
"preserveConstEnums": true,
- "skipLibCheck": true
+ "skipLibCheck": true,
},
"include": ["./src"],
- "exclude": ["./src/__tests__"]
+ "exclude": ["./src/__tests__"],
}
diff --git a/packages/taro-webpack5-runner/tsconfig.json b/packages/taro-webpack5-runner/tsconfig.json
index 23f3e910c69c..f3a1783b76b3 100644
--- a/packages/taro-webpack5-runner/tsconfig.json
+++ b/packages/taro-webpack5-runner/tsconfig.json
@@ -10,7 +10,7 @@
"esModuleInterop": true,
"paths": {
"webpack": ["./node_modules/webpack"],
- "webpack-dev-server": ["./node_modules/@types/webpack-dev-server"],
+ "webpack-dev-server": ["./node_modules/@types/webpack-dev-server", "./node_modules/webpack-dev-server"],
},
"preserveConstEnums": true,
"skipLibCheck": true
@@ -18,6 +18,6 @@
"include": ["./src", "./types"],
"exclude": [
"./src/__tests__",
- "./src/template/comp.ts"
- ]
+ "./src/template/comp.ts",
+ ],
}
diff --git a/yarn.lock b/yarn.lock
index c905efadb659..2e195116e0e7 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4844,7 +4844,7 @@
tapable "^2.2.0"
webpack "^5"
-"@types/webpack@^4", "@types/webpack@^4.41.8":
+"@types/webpack@4", "@types/webpack@^4", "@types/webpack@^4.41.8":
version "4.41.32"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.32.tgz#a7bab03b72904070162b2f169415492209e94212"
integrity sha512-cb+0ioil/7oz5//7tZUSwbrSAN/NWHrQylz5cW8G0dWTcF/g+/dSdMlKVZspBYuMAN1+WnwHrkxiRrLcwd0Heg==
|
d6f006f316b21521b675e74cba44e2aa068ce013
|
2023-02-01 15:33:06
|
Zakary
|
fix(runner): webpack4 需要对组件库处理
| false
|
webpack4 需要对组件库处理
|
fix
|
diff --git a/packages/taro-webpack-runner/src/util/chain.ts b/packages/taro-webpack-runner/src/util/chain.ts
index 562ce4a42b76..f7c1b8306fc0 100644
--- a/packages/taro-webpack-runner/src/util/chain.ts
+++ b/packages/taro-webpack-runner/src/util/chain.ts
@@ -492,7 +492,7 @@ export const parseModule = (appPath: string, {
*/
scriptRule.exclude = [filename =>
/css-loader/.test(filename)
- || /@tarojs[\\/]components/.test(filename)
+ // || /@tarojs[\\/]components/.test(filename) Note: stencil 2.14 开始使用了 import.meta.url 需要额外处理
|| (/node_modules/.test(filename) && !(/taro/.test(filename) || /inversify/.test(filename)))]
}
|
6f13d82b14bd0d50d369aca48febaf89b0c714b0
|
2023-07-21 07:26:08
|
yechunxi
|
fix(rn): 单页面引入react-navigation导致体积过大问题(#14079) (#14199)
| false
|
单页面引入react-navigation导致体积过大问题(#14079) (#14199)
|
fix
|
diff --git a/packages/taro-components-rn/src/components/Navigator/index.tsx b/packages/taro-components-rn/src/components/Navigator/index.tsx
index 031caf2f1a70..6667c814e034 100644
--- a/packages/taro-components-rn/src/components/Navigator/index.tsx
+++ b/packages/taro-components-rn/src/components/Navigator/index.tsx
@@ -1,18 +1,21 @@
import React, {
useCallback,
} from 'react'
-import {
- navigateTo,
- navigateBack,
- redirectTo,
- switchTab,
- reLaunch,
-} from '@tarojs/router-rn'
import type { NavigatorProps } from '@tarojs/components/types/Navigator'
-
import View from '../View'
import { omit } from '../../utils'
+let navigateTo, navigateBack, redirectTo, switchTab, reLaunch
+try {
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
+ const routerObj = require('@tarojs/router-rn')
+ navigateTo = routerObj?.navigateTo
+ navigateBack = routerObj?.navigateBack
+ redirectTo = routerObj?.redirectTo
+ switchTab = routerObj?.switchTab
+ reLaunch = routerObj?.reLaunch
+} catch (error) {}
+
export default function Navigator (props: NavigatorProps) {
const {
url = '',
diff --git a/packages/taro-rn-supporter/src/Support.ts b/packages/taro-rn-supporter/src/Support.ts
index 93fab856be9b..8bece7cc8096 100644
--- a/packages/taro-rn-supporter/src/Support.ts
+++ b/packages/taro-rn-supporter/src/Support.ts
@@ -7,7 +7,7 @@ import { ConditionalFileStore } from './conditional-file-store'
import { assetExts } from './defaults'
import { getReactNativeVersion, handleFile, handleTaroFile, searchReactNativeModule } from './taroResolver'
import { TerminalReporter } from './terminal-reporter'
-import { getProjectConfig, getRNConfig } from './utils'
+import { getBlockList, getProjectConfig, getRNConfig } from './utils'
const reactNativePath: string = resolveReactNativePath(findProjectRoot())
@@ -43,6 +43,7 @@ export function getTransformer (opt: Options = {}) {
export function getResolver (opt: Options = {}) {
const rnConfig = getRNConfig()
+ const blockList = getBlockList()
const handleEntryFile = (opt.fromRunner ?? true) ? handleTaroFile : handleFile
const resolver: any = {
sourceExts: ['ts', 'tsx', 'js', 'jsx', 'scss', 'sass', 'less', 'css', 'pcss', 'json', 'styl', 'cjs', 'svgx'],
@@ -53,6 +54,9 @@ export function getResolver (opt: Options = {}) {
resolver.assetExts = assetExts.filter(ext => ext !== 'svg')
resolver.sourceExts.push('svg')
}
+ if(blockList.length > 0){
+ resolver.blockList = blockList
+ }
// 兼容0.60
const rnVersion = getReactNativeVersion()
if (rnVersion && (rnVersion.major === 0) && (rnVersion.minor === 60)) {
diff --git a/packages/taro-rn-supporter/src/utils.ts b/packages/taro-rn-supporter/src/utils.ts
index e7fd585c8952..8800e81447ae 100644
--- a/packages/taro-rn-supporter/src/utils.ts
+++ b/packages/taro-rn-supporter/src/utils.ts
@@ -188,7 +188,22 @@ function includes (filePath: string): boolean {
return Boolean(res)
}
+// 获取resolver 需要过滤的文件
+function getBlockList (){
+ const regExp: Array<RegExp> = []
+ const config = getProjectConfig()
+ const srcDir = config?.sourceRoot ?? 'src'
+ const path = `${process.cwd()}/${srcDir}/app.config`
+ const configPath = helper.resolveMainFilePath(path)
+ const appConfig = helper.readConfig(configPath)
+ if( appConfig?.pages?.length === 1 && !!appConfig?.rn?.singleMode){
+ regExp.push(/@tarojs\/router-rn/)
+ }
+ return regExp
+}
+
export {
+ getBlockList,
getProjectConfig,
getRNConfig,
includes,
@@ -196,8 +211,7 @@ export {
isTaroRunner,
resolveExtFile,
resolvePathFromAlias,
- setFromRunner
-}
+ setFromRunner }
export function getOpenHost () {
let result
diff --git a/packages/taro-rn-transformer/__tests__/__snapshots__/app.spec.ts.snap b/packages/taro-rn-transformer/__tests__/__snapshots__/app.spec.ts.snap
index fe0b2292de2b..c3f60539a03c 100644
--- a/packages/taro-rn-transformer/__tests__/__snapshots__/app.spec.ts.snap
+++ b/packages/taro-rn-transformer/__tests__/__snapshots__/app.spec.ts.snap
@@ -15,6 +15,6 @@ exports[`app-loader app 1`] = `
const config = { appConfig: { ...buildConfig, ...AppComponentConfig } }
global.__taroAppConfig = config
config['pageList'] = [{name:'pagesIndexIndex',pagePath:'/pages/index/index',component:createPageConfig(pagesIndexIndex,{...pagesIndexIndexConfig,pagePath:'/pages/index/index'})},{name:'pagesExpoIndex',pagePath:'/pages/expo/index',component:createPageConfig(pagesExpoIndex,{...pagesExpoIndexConfig,pagePath:'/pages/expo/index'})},{name:'pagesAppIndex',pagePath:'/pages/app/index',component:createPageConfig(pagesAppIndex,{...pagesAppIndexConfig,pagePath:'/pages/app/index'})},{name:'pagesAppText',pagePath:'/pages/app/text',component:createPageConfig(pagesAppText,{...pagesAppTextConfig,pagePath:'/pages/app/text'})},{name:'package1PagesSubTest1',pagePath:'/package1/pages/sub/test1',component:createPageConfig(package1PagesSubTest1,{...package1PagesSubTest1Config,pagePath:'/package1/pages/sub/test1'})},{name:'package1PagesSubApp',pagePath:'/package1/pages/sub/app',component:createPageConfig(package1PagesSubApp,{...package1PagesSubAppConfig,pagePath:'/package1/pages/sub/app'})}]
- AppRegistry.registerComponent('taroDemo',() => createReactNativeApp(Component,config))
+ AppRegistry.registerComponent('taroDemo',() => createReactNativeApp(Component,config,createPageConfig(pagesIndexIndex,{...pagesIndexIndexConfig,pagePath:'/pages/index/index'})))
"
`;
diff --git a/packages/taro-rn-transformer/src/app.ts b/packages/taro-rn-transformer/src/app.ts
index 0b893fef40da..0c729ba3f658 100644
--- a/packages/taro-rn-transformer/src/app.ts
+++ b/packages/taro-rn-transformer/src/app.ts
@@ -37,10 +37,16 @@ function getPagesResource (appPath: string, basePath: string, pathPrefix: string
}
}
-function getPageScreen (pagePath: string) {
+function getPageComponent (pagePath: string){
const screen = camelCase(pagePath)
const screenConfigName = `${screen}Config`
- return `{name:'${screen}',pagePath:'${pagePath}',component:createPageConfig(${screen},{...${screenConfigName},pagePath:'${pagePath}'})}`
+ return `createPageConfig(${screen},{...${screenConfigName},pagePath:'${pagePath}'})`
+}
+
+function getPageScreen (pagePath: string) {
+ const screen = camelCase(pagePath)
+ const screenComponent = getPageComponent(pagePath)
+ return `{name:'${screen}',pagePath:'${pagePath}',component:${screenComponent}}`
}
export function getAppConfig (appPath: string) {
@@ -119,6 +125,7 @@ export default function generateEntry ({
const appComponentPath = `./${sourceDir}/${entryName}`
const appTabBar = getFormatTabBar(appPath, basePath)
+ const firstPage = getPageComponent(routeList[0])
const code = `import 'react-native-gesture-handler'
import { AppRegistry } from 'react-native'
@@ -134,7 +141,7 @@ export default function generateEntry ({
const config = { appConfig: { ...buildConfig, ...AppComponentConfig } }
global.__taroAppConfig = config
config['pageList'] = [${routeList.map(pageItem => getPageScreen(pageItem))}]
- AppRegistry.registerComponent('${appName}',() => createReactNativeApp(Component,config))
+ AppRegistry.registerComponent('${appName}',() => createReactNativeApp(Component,config,${firstPage}))
`
return code
}
diff --git a/packages/taro-router-rn/src/provider.ts b/packages/taro-router-rn/src/provider.ts
index 146b338c6899..d7945ac96e60 100644
--- a/packages/taro-router-rn/src/provider.ts
+++ b/packages/taro-router-rn/src/provider.ts
@@ -25,18 +25,20 @@ export class PageProvider extends React.Component<any> {
componentDidMount (): void {
const { navigation } = this.props
- this.unSubscribleFocus = this.props.navigation.addListener('focus', () => {
- if (navigationRef && navigationRef?.current) {
- navigationRef.current.setOptions = navigation.setOptions
- }
- // 若是tabBar页面,确保tabbar内容最新
- if (this.isTabBarPage()) {
- const tabBarVisible = getTabVisible()
- navigation.setOptions({
- tabBarVisible: tabBarVisible
- })
- }
- })
+ if(navigation){
+ this.unSubscribleFocus = this.props.navigation.addListener('focus', () => {
+ if (navigationRef && navigationRef?.current) {
+ navigationRef.current.setOptions = navigation.setOptions
+ }
+ // 若是tabBar页面,确保tabbar内容最新
+ if (this.isTabBarPage()) {
+ const tabBarVisible = getTabVisible()
+ navigation.setOptions({
+ tabBarVisible: tabBarVisible
+ })
+ }
+ })
+ }
}
componentWillUnmount (): void {
diff --git a/packages/taro-runtime-rn/src/EventChannel.ts b/packages/taro-runtime-rn/src/EventChannel.ts
index 8017a19d6749..bb6a2a35d7da 100644
--- a/packages/taro-runtime-rn/src/EventChannel.ts
+++ b/packages/taro-runtime-rn/src/EventChannel.ts
@@ -1,5 +1,3 @@
-import { getRouteEventChannel } from '@tarojs/router-rn'
-
import { Events } from './emmiter'
interface ExeListItem {
@@ -61,8 +59,6 @@ class RouteEvts extends Events {
const routeChannel: RouteEvt = new RouteEvts()
-getRouteEventChannel(routeChannel)
-
export default {
routeChannel,
pageChannel
diff --git a/packages/taro-runtime-rn/src/app.tsx b/packages/taro-runtime-rn/src/app.tsx
index eb9d396c9dd9..6606d63a3963 100644
--- a/packages/taro-runtime-rn/src/app.tsx
+++ b/packages/taro-runtime-rn/src/app.tsx
@@ -1,24 +1,28 @@
import { Provider as TCNProvider } from '@tarojs/components-rn'
-import { createRouter, getInitOptions, RouterConfig, RouterOption } from '@tarojs/router-rn'
-import React, { Component, ComponentProps, createRef, forwardRef } from 'react'
+import React, { Component, ComponentProps, createElement, createRef, forwardRef } from 'react'
import { RootSiblingParent } from 'react-native-root-siblings'
import { Current } from './current'
+import EventChannel from './EventChannel'
import { AppInstance, PageLifeCycle } from './instance'
import { getPageInstance } from './page'
+import { createRouter, getInitOptions, getRouteEventChannel } from './router'
import { RNAppConfig } from './types/index'
import { HOOKS_APP_ID, isFunction } from './utils'
-
export function isClassComponent (component): boolean {
- return isFunction(component?.render) ||
- !!component.prototype?.isReactComponent ||
- component.prototype instanceof Component
+ return (
+ isFunction(component?.render) || !!component.prototype?.isReactComponent || component.prototype instanceof Component
+ )
}
-
-export function createReactNativeApp (AppEntry: any, config: RNAppConfig) {
- const routerConfig: RouterConfig = {
+export function createReactNativeApp (AppEntry: any, config: RNAppConfig, FirstPage: any) {
+ const singleMode = config?.appConfig?.rn?.singleMode ?? false
+ const needNavigate = config.pageList.length !== 1 || !singleMode
+ if (needNavigate) {
+ getRouteEventChannel(EventChannel.routeChannel)
+ }
+ const routerConfig: any = {
tabBar: config.appConfig.tabBar,
pages: config.pageList,
entryPagePath: config.appConfig.entryPagePath,
@@ -29,36 +33,35 @@ export function createReactNativeApp (AppEntry: any, config: RNAppConfig) {
const appRef = createRef<AppInstance>()
const isReactComponent = isClassComponent(AppEntry)
- let entryComponent:any = AppEntry
- if(!isReactComponent){
+ let entryComponent: any = AppEntry
+ if (!isReactComponent) {
// eslint-disable-next-line react/display-name
entryComponent = forwardRef((props, ref) => {
- return <AppEntry forwardRef={ref} {...props} />
+ return <AppEntry forwardRef={ref} {...props} />
})
}
-
const NewAppComponent = (AppComponent) => {
- return class Entry extends Component <any, any> {
-
- constructor (props){
+ return class Entry extends Component<any, any> {
+ constructor (props) {
super(props)
const { initPath = '', initParams = {} } = this.props
routerConfig.initPath = initPath
routerConfig.initParams = initParams
-
}
componentDidMount () {
- const options = getInitOptions(routerConfig)
- triggerAppLifecycle('onLaunch',options)
- triggerAppLifecycle('componentDidShow',options)
-
+ let options: any = {}
+ if (needNavigate) {
+ options = getInitOptions(routerConfig)
+ }
+ triggerAppLifecycle('onLaunch', options)
+ triggerAppLifecycle('componentDidShow', options)
}
// 导航onUnhandledAction
- onUnhandledAction (options){
- triggerAppLifecycle('onPageNotFound',options)
+ onUnhandledAction (options) {
+ triggerAppLifecycle('onPageNotFound', options)
}
render () {
@@ -69,17 +72,26 @@ export function createReactNativeApp (AppEntry: any, config: RNAppConfig) {
...this.props
}
- const routerOptions: RouterOption = {
- onUnhandledAction: this.onUnhandledAction
+ let routerOptions: any = {}
+ if (needNavigate) {
+ routerOptions = {
+ onUnhandledAction: this.onUnhandledAction
+ }
}
-
- return <RootSiblingParent>
- <TCNProvider {...this.props}>
- <AppComponent {...appProps} ref={appRef}>
- {createRouter(routerConfig, routerOptions)}
- </AppComponent>
- </TCNProvider>
- </RootSiblingParent>
+
+ const child = needNavigate
+ ? createRouter(routerConfig, routerOptions)
+ : createElement(FirstPage, { ...this.props }, [])
+
+ return createElement(
+ RootSiblingParent,
+ null,
+ createElement(
+ TCNProvider,
+ { ...this.props },
+ createElement(AppComponent, { ...appProps, ref: appRef }, child)
+ )
+ )
}
}
}
@@ -87,54 +99,57 @@ export function createReactNativeApp (AppEntry: any, config: RNAppConfig) {
const App = NewAppComponent(entryComponent)
// 与小程序端实例保持一致
- const appInst = Object.create({}, {
- config: {
- writable: true,
- enumerable: true,
- configurable: true,
- value: config.appConfig
- },
- onLaunch: {
- enumerable: true,
- writable: true,
- value (options) {
- triggerAppLifecycle('onLaunch', options)
- }
- },
- onShow: {
- enumerable: true,
- writable: true,
- value (options) {
- triggerAppLifecycle('componentDidShow', options)
- }
- },
- onHide: {
- enumerable: true,
- writable: true,
- value (options: unknown) {
- triggerAppLifecycle('componentDidHide',options)
- }
- },
- onPageNotFound: {
- enumerable: true,
- writable: true,
- value (options) {
- triggerAppLifecycle('onPageNotFound', options)
+ const appInst = Object.create(
+ {},
+ {
+ config: {
+ writable: true,
+ enumerable: true,
+ configurable: true,
+ value: config.appConfig
+ },
+ onLaunch: {
+ enumerable: true,
+ writable: true,
+ value (options) {
+ triggerAppLifecycle('onLaunch', options)
+ }
+ },
+ onShow: {
+ enumerable: true,
+ writable: true,
+ value (options) {
+ triggerAppLifecycle('componentDidShow', options)
+ }
+ },
+ onHide: {
+ enumerable: true,
+ writable: true,
+ value (options: unknown) {
+ triggerAppLifecycle('componentDidHide', options)
+ }
+ },
+ onPageNotFound: {
+ enumerable: true,
+ writable: true,
+ value (options) {
+ triggerAppLifecycle('onPageNotFound', options)
+ }
}
- },
- })
+ }
+ )
- function triggerAppLifecycle (lifecycle: keyof PageLifeCycle | keyof AppInstance, ...args){
+ function triggerAppLifecycle (lifecycle: keyof PageLifeCycle | keyof AppInstance, ...args) {
try {
const app = appRef.current
- if(isReactComponent){
+ if (isReactComponent) {
app?.[lifecycle] && app?.[lifecycle](...args)
- }else{
+ } else {
const instance = getPageInstance(HOOKS_APP_ID)
- if(instance){
+ if (instance) {
const func = instance[lifecycle]
if (Array.isArray(func)) {
- func.forEach(cb => cb.apply(app, args))
+ func.forEach((cb) => cb.apply(app, args))
}
}
}
diff --git a/packages/taro-runtime-rn/src/current.ts b/packages/taro-runtime-rn/src/current.ts
index 2ec642f546bf..4bbb084ff77e 100644
--- a/packages/taro-runtime-rn/src/current.ts
+++ b/packages/taro-runtime-rn/src/current.ts
@@ -1,7 +1,7 @@
-import { navigationRef as rnNavigationRef } from '@tarojs/router-rn'
import * as React from 'react'
import { AppInstance, PageInstance } from './instance'
+import { rnNavigationRef } from './router'
interface Router {
params: Record<string, unknown>
diff --git a/packages/taro-runtime-rn/src/index.ts b/packages/taro-runtime-rn/src/index.ts
index 073b99a7014e..825a26071bca 100644
--- a/packages/taro-runtime-rn/src/index.ts
+++ b/packages/taro-runtime-rn/src/index.ts
@@ -20,10 +20,6 @@ export {
startPullDownRefresh,
stopPullDownRefresh
} from './page'
-export {
- scalePx2dp,
- scaleVu2dp
-} from './scale2dp'
export {
hideNavigationBarLoading,
hideTabBar,
@@ -42,4 +38,8 @@ export {
showTabBar,
showTabBarRedDot,
switchTab
-} from '@tarojs/router-rn'
+} from './router'
+export {
+ scalePx2dp,
+ scaleVu2dp
+} from './scale2dp'
diff --git a/packages/taro-runtime-rn/src/page.ts b/packages/taro-runtime-rn/src/page.ts
index ad3551be0413..4c3303da26b7 100644
--- a/packages/taro-runtime-rn/src/page.ts
+++ b/packages/taro-runtime-rn/src/page.ts
@@ -1,4 +1,3 @@
-import { getCurrentRoute, isTabPage, PageProvider } from '@tarojs/router-rn'
import { Component, Context, createContext, createElement, createRef, forwardRef, RefObject } from 'react'
import { AppState, Dimensions, EmitterSubscription, RefreshControl, ScrollView } from 'react-native'
@@ -7,7 +6,16 @@ import { Current } from './current'
import { eventCenter } from './emmiter'
import EventChannel from './EventChannel'
import { Instance, PageInstance } from './instance'
-import { BackgroundOption, BaseOption, CallbackResult, HooksMethods, PageConfig, ScrollOption, TextStyleOption } from './types/index'
+import { getCurrentRoute, isTabPage, PageProvider } from './router'
+import {
+ BackgroundOption,
+ BaseOption,
+ CallbackResult,
+ HooksMethods,
+ PageConfig,
+ ScrollOption,
+ TextStyleOption
+} from './types/index'
import { EMPTY_OBJ, errorHandler, getPageStr, incrementId, isArray, isFunction, successHandler } from './utils'
const compId = incrementId()
@@ -46,7 +54,7 @@ function safeExecute (path: string, lifecycle: keyof Instance, ...args: unknown[
const func = getLifecyle(instance, lifecycle)
if (isArray(func)) {
- const res = func.map(fn => fn.apply(instance, args))
+ const res = func.map((fn) => fn.apply(instance, args))
return res[0]
}
if (!isFunction(func)) {
@@ -67,10 +75,11 @@ AppState.addEventListener('change', (nextAppState) => {
const { page, app, router } = Current
if (!page) return
if (appState.match(/inactive|background/) && nextAppState === 'active') {
- app?.onShow && app.onShow({
- path: router?.path,
- query: router?.params
- })
+ app?.onShow &&
+ app.onShow({
+ path: router?.path,
+ query: router?.params
+ })
if (!page.__isReactComponent && page.__safeExecute) {
page.__safeExecute('componentDidShow')
} else if (page.onShow) {
@@ -132,7 +141,8 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
constructor (props: any) {
super(props)
const refreshStyle = globalAny?.__taroRefreshStyle ?? {}
- const backgroundTextStyle = pageConfig.backgroundTextStyle || globalAny.__taroAppConfig?.appConfig?.window?.backgroundTextStyle || 'dark'
+ const backgroundTextStyle =
+ pageConfig.backgroundTextStyle || globalAny.__taroAppConfig?.appConfig?.window?.backgroundTextStyle || 'dark'
this.state = {
refreshing: false, // 刷新指示器
textColor: refreshStyle.textColor || (backgroundTextStyle === 'dark' ? '#000000' : '#ffffff'),
@@ -154,16 +164,15 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
this.unSubscribleTabPress = navigation.addListener('tabPress', () => this.onTabItemTap())
this.unSubscribleFocus = navigation.addListener('focus', () => this.onFocusChange())
this.unSubscribleBlur = navigation.addListener('blur', () => this.onBlurChange())
+ // 如果是tabbar页面,因为tabbar是懒加载的,第一次点击事件还未监听,不会触发,初始化触发一下
+ const lazy = globalAny.__taroAppConfig?.appConfig?.rn?.tabOptions?.lazy ?? true
+ if (isTabPage() && lazy) {
+ this.onTabItemTap()
+ }
}
eventCenter.on('__taroPullDownRefresh', this.pullDownRefresh, this)
eventCenter.on('__taroPageScrollTo', this.pageToScroll, this)
eventCenter.on('__taroSetRefreshStyle', this.setRefreshStyle, this)
-
- // 如果是tabbar页面,因为tabbar是懒加载的,第一次点击事件还未监听,不会触发,初始化触发一下
- const lazy = globalAny.__taroAppConfig?.appConfig?.rn?.tabOptions?.lazy ?? true
- if(isTabPage() && lazy){
- this.onTabItemTap()
- }
}
componentWillUnmount () {
@@ -186,7 +195,7 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
setPageInstance () {
const pageRef = this.screenRef
const pageId = this.pageId
- const { params = {}, key = '' } = this.props.route
+ const { params = {}, key = '' } = this.props.route ?? {}
// 和小程序的page实例保持一致
const inst: PageInstance = {
config: pageConfig,
@@ -308,7 +317,7 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
try {
this.handleHooksEvent('componentDidShow')
// 实现 useReady hook,遵循小程序事件机制,在useDidShow之后触发
- if(!this.isPageReady){
+ if (!this.isPageReady) {
this.handleHooksEvent('onReady')
this.isPageReady = true
}
@@ -321,20 +330,24 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
onBlurChange () {
try {
this.handleHooksEvent('componentDidHide')
- if (this.screenRef?.current?.componentDidHide) { this.screenRef?.current?.componentDidHide() }
+ if (this.screenRef?.current?.componentDidHide) {
+ this.screenRef?.current?.componentDidHide()
+ }
} catch (err) {
throw new Error(err)
}
}
onPageScroll (e) {
- if(!e?.nativeEvent) return
+ if (!e?.nativeEvent) return
const { contentOffset } = e.nativeEvent
const scrollTop = contentOffset.y
if (scrollTop < 0) return
try {
this.handleHooksEvent('onPageScroll', { scrollTop })
- if (this.screenRef?.current?.onPageScroll) { this.screenRef?.current?.onPageScroll({ scrollTop }) }
+ if (this.screenRef?.current?.onPageScroll) {
+ this.screenRef?.current?.onPageScroll({ scrollTop })
+ }
} catch (err) {
throw new Error(err)
}
@@ -342,13 +355,15 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
// 监听的onMomentumScrollEnd
onReachBottom (e) {
- if(!e?.nativeEvent) return
+ if (!e?.nativeEvent) return
const { onReachBottomDistance = 50 } = pageConfig
const { layoutMeasurement, contentSize, contentOffset } = e.nativeEvent
if (contentOffset?.y + layoutMeasurement?.height + onReachBottomDistance >= contentSize.height) {
try {
this.handleHooksEvent('onReachBottom')
- if (this.screenRef?.current?.onReachBottom) { this.screenRef?.current?.onReachBottom() }
+ if (this.screenRef?.current?.onReachBottom) {
+ this.screenRef?.current?.onReachBottom()
+ }
} catch (err) {
throw new Error(err)
}
@@ -360,7 +375,9 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
this.setState({ refreshing: true })
try {
this.handleHooksEvent('onPullDownRefresh')
- if (this.screenRef?.current?.onPullDownRefresh) { this.screenRef?.current?.onPullDownRefresh() }
+ if (this.screenRef?.current?.onPullDownRefresh) {
+ this.screenRef?.current?.onPullDownRefresh()
+ }
} catch (e) {
throw new Error(e)
} finally {
@@ -372,7 +389,9 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
try {
const item = this.getTabItem(pagePath)
this.handleHooksEvent('onTabItemTap', { ...item })
- if (this.screenRef?.current?.onTabItemTap) { this.screenRef?.current?.onTabItemTap(item) }
+ if (this.screenRef?.current?.onTabItemTap) {
+ this.screenRef?.current?.onTabItemTap(item)
+ }
} catch (error) {
throw new Error(error)
}
@@ -408,47 +427,58 @@ export function createPageConfig (Page: any, pageConfig: PageConfig): any {
refreshPullDown () {
const { refreshing, textColor, backgroundColor } = this.state
- return createElement(RefreshControl, {
- refreshing: refreshing,
- enabled: true,
- titleColor: textColor,
- tintColor: textColor,
- colors: [backgroundColor],
- onRefresh: () => this.onPullDownRefresh()
- }, null)
+ return createElement(
+ RefreshControl,
+ {
+ refreshing: refreshing,
+ enabled: true,
+ titleColor: textColor,
+ tintColor: textColor,
+ colors: [backgroundColor],
+ onRefresh: () => this.onPullDownRefresh()
+ },
+ null
+ )
}
createPage () {
- return h(PageProvider, { currentPath: pagePath, pageConfig, ...this.props },
- h(PageContext.Provider, { value: this.pageId }, h(Screen,
- { ...this.props, ref: this.screenRef })
+ if (PageProvider) {
+ return h(
+ PageProvider,
+ { currentPath: pagePath, pageConfig, ...this.props },
+ h(PageContext.Provider, { value: this.pageId }, h(Screen, { ...this.props, ref: this.screenRef }))
)
- )
+ }
+ return h(PageContext.Provider, { value: this.pageId }, h(Screen, { ...this.props, ref: this.screenRef }))
}
createScrollPage () {
let bgColor = pageConfig.backgroundColor ? pageConfig.backgroundColor : ''
const windowOptions = globalAny.__taroAppConfig?.appConfig?.window || {}
- const useNativeStack = globalAny.__taroAppConfig?.appConfig?.rn?.useNativeStack
+ const useNativeStack = globalAny.__taroAppConfig?.appConfig?.rn?.useNativeStack
if (!bgColor && windowOptions?.backgroundColor) {
bgColor = windowOptions?.backgroundColor
}
const refresh = this.isEnablePullDown() ? { refreshControl: this.refreshPullDown() } : {}
- return h(ScrollView, {
- style: [{ flex: 1 }, (bgColor ? { backgroundColor: bgColor } : {})],
- contentContainerStyle: useNativeStack ? {} : { minHeight: '100%' },
- ref: this.pageScrollView,
- scrollEventThrottle: 8,
- ...refresh,
- onScroll: (e) => this.onPageScroll(e),
- onMomentumScrollEnd: (e) => this.onReachBottom(e),
- nestedScrollEnabled: true,
- }, this.createPage())
+ return h(
+ ScrollView,
+ {
+ style: [{ flex: 1 }, bgColor ? { backgroundColor: bgColor } : {}],
+ contentContainerStyle: useNativeStack ? {} : { minHeight: '100%' },
+ ref: this.pageScrollView,
+ scrollEventThrottle: 8,
+ ...refresh,
+ onScroll: (e) => this.onPageScroll(e),
+ onMomentumScrollEnd: (e) => this.onReachBottom(e),
+ nestedScrollEnabled: true
+ },
+ this.createPage()
+ )
}
render () {
const { disableScroll = false } = pageConfig
- return (!disableScroll ? this.createScrollPage() : this.createPage())
+ return !disableScroll ? this.createScrollPage() : this.createPage()
}
}
}
@@ -549,11 +579,12 @@ export function getCurrentPages () {
const pages: PageInstance[] = []
const routes = getCurrentRoute()
if (routes && routes.length > 0) {
- routes.forEach(item => {
+ routes.forEach((item) => {
const inst = getPageObject(item)
inst && pages.push(inst)
})
- } else { // 第一次初始化时,getCurrentRoute会为空
+ } else {
+ // 第一次初始化时,getCurrentRoute会为空
const inst = Current.page
inst && pages.push(inst)
}
diff --git a/packages/taro-runtime-rn/src/router.ts b/packages/taro-runtime-rn/src/router.ts
new file mode 100644
index 000000000000..02536c098be8
--- /dev/null
+++ b/packages/taro-runtime-rn/src/router.ts
@@ -0,0 +1,51 @@
+/**
+ * router-rn 接口都改为require 引入, 单页不引用的router
+ *
+ */
+let routerObj: any = {}
+try {
+ routerObj = require('@tarojs/router-rn')
+ // eslint-disable-next-line
+} catch (e) {}
+
+function getApi (key){
+ if (!routerObj?.[key]) {
+ return () => {
+ console.error(`Single page can not support ${key}, if you have multiple pages configured, you can try restart and reset cache`)
+ }
+ }
+ return routerObj?.[key]
+}
+
+export const rnNavigationRef = routerObj?.navigationRef ?? null
+export const PageProvider = routerObj?.PageProvider ?? null
+
+export const getRouteEventChannel = getApi('getRouteEventChannel')
+export const getCurrentRoute = getApi('getCurrentRoute')
+export const isTabPage = getApi('isTabPage')
+
+export const createRouter = getApi('createRouter')
+export const getInitOptions = getApi('getInitOptions')
+
+export const hideNavigationBarLoading = getApi('hideNavigationBarLoading')
+export const hideTabBar = getApi('hideTabBar')
+export const hideTabBarRedDot = getApi('hideTabBarRedDot')
+export const navigateBack = getApi('navigateBack')
+export const navigateTo = getApi('navigateTo')
+export const redirectTo = getApi('redirectTo')
+export const reLaunch = getApi('reLaunch')
+export const switchTab = getApi('switchTab')
+export const removeTabBarBadge = getApi('removeTabBarBadge')
+export const setNavigationBarColor = getApi('setNavigationBarColor')
+export const setNavigationBarTitle = getApi('setNavigationBarTitle')
+export const setTabBarBadge = getApi('setTabBarBadge')
+export const setTabBarItem = getApi('setTabBarItem')
+export const setTabBarStyle = getApi('setTabBarStyle')
+export const showNavigationBarLoading = getApi('showNavigationBarLoading')
+export const showTabBar = getApi('showTabBar')
+export const showTabBarRedDot = getApi('showTabBarRedDot')
+
+
+
+
+
|
46604f5003bdf0afe2cede73f69a44a4c16638d0
|
2019-06-25 14:03:56
|
yuche
|
fix(transformer): 循环没有写 return 生成匿名函数错误,close #3536
| false
|
循环没有写 return 生成匿名函数错误,close #3536
|
fix
|
diff --git a/packages/taro-transformer-wx/src/class.ts b/packages/taro-transformer-wx/src/class.ts
index 24c5cdbff3d3..e735ea34f486 100644
--- a/packages/taro-transformer-wx/src/class.ts
+++ b/packages/taro-transformer-wx/src/class.ts
@@ -270,32 +270,45 @@ class Transformer {
]
)
)])
- stemParent.insertBefore(indexKeyDecl)
- const arrayFunc = t.memberExpression(
- t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName + 'Map')),
- t.identifier(indexKey),
- true
- )
- classBody.push(
- t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier(indexKey), t.identifier('e')], t.blockStatement([
- isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement(),
- t.returnStatement(t.logicalExpression('&&', arrayFunc, t.callExpression(arrayFunc, [t.identifier('e')])))
- ]))
- )
- exprPath.replaceWith(t.callExpression(
- t.memberExpression(
- t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)),
- t.identifier('bind')
- ),
- [t.thisExpression(), t.identifier(indexKey)]
- ))
- stemParent.insertBefore(
- t.expressionStatement(t.assignmentExpression(
- '=',
- arrayFunc,
- expr
+
+ const func = loopCallExpr.node.arguments[0]
+ if (t.isArrowFunctionExpression(func)) {
+ if (!t.isBlockStatement(func.body)) {
+ func.body = t.blockStatement([
+ indexKeyDecl,
+ t.returnStatement(func.body)
+ ])
+ } else {
+ func.body.body.push(indexKeyDecl)
+ }
+ const arrayFunc = t.memberExpression(
+ t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName + 'Map')),
+ t.identifier(indexKey),
+ true
+ )
+ classBody.push(
+ t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier(indexKey), t.identifier('e')], t.blockStatement([
+ isCatch ? t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('e'), t.identifier('stopPropagation')), [])) : t.emptyStatement(),
+ t.returnStatement(t.logicalExpression('&&', arrayFunc, t.callExpression(arrayFunc, [t.identifier('e')])))
+ ]))
+ )
+ exprPath.replaceWith(t.callExpression(
+ t.memberExpression(
+ t.memberExpression(t.thisExpression(), t.identifier(anonymousFuncName)),
+ t.identifier('bind')
+ ),
+ [t.thisExpression(), t.identifier(indexKey)]
))
- )
+ func.body.body.push(
+ t.expressionStatement(t.assignmentExpression(
+ '=',
+ arrayFunc,
+ expr
+ ))
+ )
+ } else {
+ throw codeFrameError(func, '返回 JSX 的循环语句必须使用箭头函数')
+ }
} else {
classBody.push(
t.classMethod('method', t.identifier(anonymousFuncName), [t.identifier('e')], t.blockStatement([
|
373d6968548bde92ac4899bd52d6c59ab2b4cc6e
|
2018-06-10 20:09:02
|
luckyadam
|
chore(release): publish v0.0.44
| false
|
publish v0.0.44
|
chore
|
diff --git a/lerna.json b/lerna.json
index 193b99ff83c1..7672cc4e6767 100644
--- a/lerna.json
+++ b/lerna.json
@@ -26,7 +26,7 @@
"message": "chore(release): publish %s"
}
},
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"npmClient": "yarn",
"npmClientArgs": [
"--no-lockfile"
diff --git a/packages/eslint-config-taro/package.json b/packages/eslint-config-taro/package.json
index 6c5b7a6a7507..615cd035635e 100644
--- a/packages/eslint-config-taro/package.json
+++ b/packages/eslint-config-taro/package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-config-taro",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro specific linting rules for ESLint",
"main": "index.js",
"files": [
diff --git a/packages/postcss-plugin-constparse/package.json b/packages/postcss-plugin-constparse/package.json
index 79743398f855..2a78a9753230 100644
--- a/packages/postcss-plugin-constparse/package.json
+++ b/packages/postcss-plugin-constparse/package.json
@@ -1,6 +1,6 @@
{
"name": "postcss-plugin-constparse",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "parse constants defined in config",
"main": "index.js",
"author": "Simba",
diff --git a/packages/taro-async-await/package.json b/packages/taro-async-await/package.json
index 0a11ffae6cb3..33f0c0097bd0 100644
--- a/packages/taro-async-await/package.json
+++ b/packages/taro-async-await/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/async-await",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "taro async await",
"main": "index.js",
"scripts": {
diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json
index 62b9a1df47f9..c9833e44ab01 100644
--- a/packages/taro-cli/package.json
+++ b/packages/taro-cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/cli",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "cli tool for taro",
"main": "index.js",
"scripts": {
@@ -23,7 +23,7 @@
"author": "O2Team",
"license": "MIT",
"dependencies": {
- "@tarojs/transformer-wx": "0.0.44-beta.4",
+ "@tarojs/transformer-wx": "0.0.44",
"autoprefixer": "^8.4.1",
"babel-generator": "^6.26.1",
"babel-template": "^6.26.0",
diff --git a/packages/taro-components-rn/package.json b/packages/taro-components-rn/package.json
index 2198eddde68a..4ca14c426ad0 100644
--- a/packages/taro-components-rn/package.json
+++ b/packages/taro-components-rn/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components-rn",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "多端解决方案基础组件(RN)",
"main": "./src/index.js",
"scripts": {
diff --git a/packages/taro-components/package.json b/packages/taro-components/package.json
index c37f2f1beff0..95dd610930a3 100644
--- a/packages/taro-components/package.json
+++ b/packages/taro-components/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/components",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "",
"main": "./dist/index.js",
"module": "./src/components/index.js",
diff --git a/packages/taro-h5/package.json b/packages/taro-h5/package.json
index eba8b98719f2..6f281d59e298 100644
--- a/packages/taro-h5/package.json
+++ b/packages/taro-h5/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/taro-h5",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro h5 framework",
"main": "index.js",
"files": [
@@ -25,7 +25,7 @@
"nervjs": "^1.2.17"
},
"dependencies": {
- "@tarojs/taro": "0.0.44-beta.4",
+ "@tarojs/taro": "0.0.44",
"jsonp-retry": "^1.0.3",
"nervjs": "^1.2.18"
}
diff --git a/packages/taro-plugin-babel/package.json b/packages/taro-plugin-babel/package.json
index e16207252215..dc7040f4c021 100644
--- a/packages/taro-plugin-babel/package.json
+++ b/packages/taro-plugin-babel/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-babel",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro babel编译",
"main": "index.js",
"scripts": {
diff --git a/packages/taro-plugin-csso/package.json b/packages/taro-plugin-csso/package.json
index 412a1bd1903b..fa4d09d39300 100644
--- a/packages/taro-plugin-csso/package.json
+++ b/packages/taro-plugin-csso/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-csso",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro压缩CSS文件",
"main": "index.js",
"scripts": {
diff --git a/packages/taro-plugin-sass/package.json b/packages/taro-plugin-sass/package.json
index 898d91852b86..e79900f9c91e 100644
--- a/packages/taro-plugin-sass/package.json
+++ b/packages/taro-plugin-sass/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-sass",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro编译sass文件",
"main": "index.js",
"scripts": {
diff --git a/packages/taro-plugin-uglifyjs/package.json b/packages/taro-plugin-uglifyjs/package.json
index a9ffb0ce677e..5386cd430c87 100644
--- a/packages/taro-plugin-uglifyjs/package.json
+++ b/packages/taro-plugin-uglifyjs/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-uglifyjs",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro压缩JS文件",
"main": "index.js",
"scripts": {
diff --git a/packages/taro-redux/package.json b/packages/taro-redux/package.json
index 36f4cbc3e760..003eb51f02a6 100644
--- a/packages/taro-redux/package.json
+++ b/packages/taro-redux/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/redux",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Redux for Taro",
"main": "index.js",
"scripts": {
diff --git a/packages/taro-rn-runner/package.json b/packages/taro-rn-runner/package.json
index 348b29bc32c4..e0e6b69193a7 100644
--- a/packages/taro-rn-runner/package.json
+++ b/packages/taro-rn-runner/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/rn-runner",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "ReactNative build tool for taro",
"main": "index.js",
"scripts": {
diff --git a/packages/taro-rn/package.json b/packages/taro-rn/package.json
index f00e5a3c918a..ef3c69d3f3b6 100644
--- a/packages/taro-rn/package.json
+++ b/packages/taro-rn/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/taro-rn",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro RN framework",
"main": "./src/index.js",
"files": [
@@ -20,6 +20,6 @@
"author": "O2Team",
"license": "MIT",
"dependencies": {
- "@tarojs/taro": "0.0.44-beta.4"
+ "@tarojs/taro": "0.0.44"
}
}
diff --git a/packages/taro-router/package.json b/packages/taro-router/package.json
index 6156010dba8b..e4fa15e1e268 100644
--- a/packages/taro-router/package.json
+++ b/packages/taro-router/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/router",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro-router",
"main": "index.js",
"module": "dist/index.esm.js",
diff --git a/packages/taro-transformer-wx/package.json b/packages/taro-transformer-wx/package.json
index 0ca5ad97f22e..90761815ff59 100644
--- a/packages/taro-transformer-wx/package.json
+++ b/packages/taro-transformer-wx/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/transformer-wx",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Transfrom Nerv Component to Wechat mini program.",
"repository": {
"type": "git",
diff --git a/packages/taro-weapp/package.json b/packages/taro-weapp/package.json
index 5982f53b913a..5a64fde3148a 100644
--- a/packages/taro-weapp/package.json
+++ b/packages/taro-weapp/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/taro-weapp",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro weapp framework",
"main": "index.js",
"files": [
@@ -22,7 +22,7 @@
"author": "O2Team",
"license": "MIT",
"dependencies": {
- "@tarojs/taro": "0.0.44-beta.4",
+ "@tarojs/taro": "0.0.44",
"prop-types": "^15.6.1"
}
}
diff --git a/packages/taro-webpack-runner/package.json b/packages/taro-webpack-runner/package.json
index fd3909c4fb0a..0eea6dbbb9b6 100644
--- a/packages/taro-webpack-runner/package.json
+++ b/packages/taro-webpack-runner/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/webpack-runner",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "webpack runner for taro",
"main": "index.js",
"scripts": {
@@ -37,7 +37,7 @@
"opn": "^5.3.0",
"ora": "^2.1.0",
"postcss-loader": "^2.1.3",
- "postcss-plugin-constparse": "0.0.44-beta.4",
+ "postcss-plugin-constparse": "0.0.44",
"postcss-pxtransform": "^0.0.1",
"sass-loader": "^6.0.7",
"style-loader": "^0.20.3",
diff --git a/packages/taro/package.json b/packages/taro/package.json
index 447f59290559..96f1c40d5a54 100644
--- a/packages/taro/package.json
+++ b/packages/taro/package.json
@@ -1,6 +1,6 @@
{
"name": "@tarojs/taro",
- "version": "0.0.44-beta.4",
+ "version": "0.0.44",
"description": "Taro framework",
"main": "index.js",
"typings": "types/index.d.ts",
|
5ed3680fb14d191b56f75a6f6286352eb01d12f0
|
2018-09-18 18:15:38
|
Pines-Cheng
|
chore(RN): 将 taro-cli 里的 babel plugins 放入taro-cli 依赖中,省略 npmProcess 代码
| false
|
将 taro-cli 里的 babel plugins 放入taro-cli 依赖中,省略 npmProcess 代码
|
chore
|
diff --git a/packages/taro-cli/package.json b/packages/taro-cli/package.json
index 5fb7f647e5a6..27e78565d23c 100644
--- a/packages/taro-cli/package.json
+++ b/packages/taro-cli/package.json
@@ -28,7 +28,9 @@
"babel-core": "^6.26.3",
"babel-generator": "^6.26.1",
"babel-plugin-remove-dead-code": "^1.3.2",
+ "babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-define": "^1.3.0",
+ "babel-plugin-transform-jsx-to-stylesheet": "1.0.0",
"babel-template": "^6.26.0",
"babel-traverse": "^6.26.0",
"babel-types": "^6.26.0",
diff --git a/packages/taro-cli/src/rn.js b/packages/taro-cli/src/rn.js
index e57a68f1f4d5..67e0206353b4 100644
--- a/packages/taro-cli/src/rn.js
+++ b/packages/taro-cli/src/rn.js
@@ -68,10 +68,11 @@ function getJSAst (code) {
return babel.transform(code, {
parserOpts: babylonConfig,
plugins: [
- 'transform-decorators-legacy',
- [require('babel-plugin-transform-define').default, {
- 'process.env.TARO_ENV': 'rn'
- }],
+ require('babel-plugin-transform-decorators-legacy').default,
+ [
+ require('babel-plugin-transform-define').default,
+ {'process.env.TARO_ENV': 'rn'}
+ ],
require('babel-plugin-remove-dead-code').default
]
}).ast
@@ -82,12 +83,7 @@ function parseJSCode (code, filePath) {
try {
ast = getJSAst(code)
} catch (e) {
- if (e.name === 'ReferenceError') {
- npmProcess.getNpmPkgSync('babel-plugin-transform-decorators-legacy')
- ast = getJSAst(code)
- } else {
- throw e
- }
+ throw e
}
const styleFiles = []
let pages = [] // app.js 里面的config 配置里面的 pages
@@ -477,17 +473,10 @@ function parseJSCode (code, filePath) {
})
try {
ast = babel.transformFromAst(ast, code, {
- plugins: ['babel-plugin-transform-jsx-to-stylesheet']
+ plugins: [require('babel-plugin-transform-jsx-to-stylesheet')]
}).ast
} catch (e) {
- if (e.name === 'ReferenceError') {
- npmProcess.getNpmPkgSync('babel-plugin-transform-jsx-to-stylesheet')
- ast = babel.transformFromAst(ast, code, {
- plugins: ['babel-plugin-transform-jsx-to-stylesheet']
- }).ast
- } else {
- throw e
- }
+ throw e
}
return {
@@ -552,7 +541,7 @@ function buildTemp () {
if (Util.REG_STYLE.test(filePath)) {
return cb()
}
- if (Util.REG_SCRIPT.test(filePath)) {
+ if (Util.REG_SCRIPTS.test(filePath)) {
Util.printLog(Util.pocessTypeEnum.COMPILE, 'JS', filePath)
// parseJSCode
let transformResult = parseJSCode(content, filePath)
|
519b0f540184c62f24b165ff4915256ad72e1d43
|
2018-11-19 08:31:53
|
luckyadam
|
feat(cli): 小程序转 taro 代码 wxs 文件处理
| false
|
小程序转 taro 代码 wxs 文件处理
|
feat
|
diff --git a/packages/taro-cli/src/convertor.js b/packages/taro-cli/src/convertor.js
index 7c7c2ba1f0a9..b2c09c8abf03 100644
--- a/packages/taro-cli/src/convertor.js
+++ b/packages/taro-cli/src/convertor.js
@@ -62,9 +62,14 @@ function analyzeImportUrl (sourceFilePath, scriptFiles, source, value) {
}
}
let relativePath = path.relative(sourceFilePath, vpath)
+ const relativePathExtname = path.extname(relativePath)
scriptFiles.add(vpath)
relativePath = promoteRelativePath(relativePath)
- relativePath = relativePath.replace(path.extname(relativePath), '.js')
+ if (/\.wxs/.test(relativePathExtname)) {
+ relativePath += '.js'
+ } else {
+ relativePath = relativePath.replace(relativePathExtname, '.js')
+ }
source.value = relativePath
}
}
@@ -205,7 +210,11 @@ class Convertor {
return
}
const code = fs.readFileSync(file).toString()
- const outputFilePath = file.replace(this.root, this.convertDir)
+ let outputFilePath = file.replace(this.root, this.convertDir)
+ const extname = path.extname(outputFilePath)
+ if (/\.wxs/.test(extname)) {
+ outputFilePath += '.js'
+ }
const transformResult = wxTransformer({
code,
sourcePath: file,
|
2bf6af7f6049bde10fca80a865e665529826580c
|
2019-04-16 07:06:46
|
psaren
|
docs: add plugin.sass config (#2779)
| false
|
add plugin.sass config (#2779)
|
docs
|
diff --git a/docs/config-detail.md b/docs/config-detail.md
index d1d84d227e4d..8c8479696029 100644
--- a/docs/config-detail.md
+++ b/docs/config-detail.md
@@ -62,6 +62,23 @@ csso: {
}
```
+### plugins.sass
+用来配置 `sass` 工具,设置打包过程中的 SCSS 代码编译。
+具体配置可以参考[dart-sass](https://www.npmjs.com/package/dart-sass)
+v1.2.23改为用[dart-sass](https://www.npmjs.com/package/dart-sass)作编译工具
+v1.2.23前使用[node-sass](https://www.npmjs.com/package/node-sass)作编译工具
+当需要全局注入scss文件时,可以添加两个额外参数:`resource` 、 `projectDirectory` (v1.2.25开始支持),具体配置方式如下:
+```jsx
+sass: {
+ resource: path.resolve(__dirname, '..', 'src/styles/variable.scss'),
+ // OR
+ // resource: ['path/to/global.variable.scss', 'path/to/global.mixin.scss']
+ projectDirectory: path.resolve(__dirname, '..')
+ }
+```
+resource: 如果要引入多个文件,支持数组形式传入。
+projectDirectory: 项目根目录的绝对地址(若为小程序云开发模板,则应该是client目录)。
+
## env
用来设置一些环境变量如 `process.env.NODE_ENV`,例如我们想设置区分预览、打包来做些不同的操作,可以如下配置:
|
dc7c2bba05b2e239922b215b06f1d1ca62003c58
|
2023-09-18 17:02:50
|
xuanzebin
|
feat: 初步完善按钮组件
| false
|
初步完善按钮组件
|
feat
|
diff --git a/packages/taro-platform-harmony/src/components/components-harmony-ets/button.ets b/packages/taro-platform-harmony/src/components/components-harmony-ets/button.ets
new file mode 100644
index 000000000000..3b28dd87e9d4
--- /dev/null
+++ b/packages/taro-platform-harmony/src/components/components-harmony-ets/button.ets
@@ -0,0 +1,126 @@
+// @ts-ignore
+import { eventHandler, NodeType } from '@tarojs/runtime'
+
+import { createNode } from './render'
+import { FlexManager } from './utils/FlexManager'
+import { AttributeManager } from './utils/AttributeManager'
+
+import type { TaroButtonElement } from '../runtime'
+import { BUTTON_THEME_COLOR } from './utils/constant/style'
+
+@Extend(Button)
+function attrs ({
+ flexSize,
+ alignSelf,
+ size,
+ margin,
+ padding,
+ zIndex,
+}) {
+ .size(size)
+ .zIndex(zIndex)
+ .margin(margin)
+ .padding(padding)
+ .alignSelf(alignSelf)
+ .flexGrow(flexSize[0])
+ .flexShrink(flexSize[1])
+ .flexBasis(flexSize[2])
+}
+
+@Extend(Button)
+function themeStyles({
+ isPlain,
+ fontColor,
+ backgroundColor,
+}) {
+ .backgroundColor(isPlain ? 'transparent' : backgroundColor)
+ .borderColor(backgroundColor)
+ .fontColor(fontColor)
+}
+
+function getThemeAttributes (node: TaroButtonElement) {
+ const { _st, _attrs } = node
+ const isPlain = _attrs.plain
+ const type = _attrs.type || 'default'
+
+ return {
+ isPlain,
+ backgroundColor: _st.backgroundColor || BUTTON_THEME_COLOR[type].background,
+ fontColor: AttributeManager.getNodeStyle(_st, 'color', BUTTON_THEME_COLOR[type].text),
+ }
+}
+
+function getAttributes (node: TaroButtonElement) {
+ const { _st } = node
+
+ return {
+ size: {
+ width: AttributeManager.getNodeStyle(_st, 'width', 0),
+ height: AttributeManager.getNodeStyle(_st, 'height', 0)
+ },
+ alignSelf: ItemAlign.Auto,
+ flexSize: FlexManager.flexSize(_st),
+ zIndex: AttributeManager.getNodeStyle(_st, 'zIndex'),
+ margin: AttributeManager.getNodeMarginOrPaddingData(_st, 'margin'),
+ padding: AttributeManager.getNodeMarginOrPaddingData(_st, 'padding'),
+ }
+}
+
+@Component
+struct TaroButton {
+ @ObjectLink node: TaroButtonElement
+
+ @Styles defaultEvent () {
+ .onClick(e => eventHandler(e, 'click', this.node))
+ }
+
+ @Builder createButtonElement ($$: { instance }) {
+ Button() {
+ Row() {
+ if ($$.instance._attrs.loading) {
+ LoadingProgress()
+ .width(20).height(20)
+ .color(getThemeAttributes($$.instance).fontColor)
+ }
+ ForEach($$.instance.childNodes, item => {
+ createNode(item)
+ }, item => item._nid)
+ }
+ }
+ .defaultEvent()
+ .attrs(getAttributes($$.instance))
+ .themeStyles(getThemeAttributes($$.instance))
+ }
+
+ @Builder createImageElementWithPosition ($$: { instance, top, left }) {
+ if (AttributeManager.getNodeStyle($$.instance._st, 'position') === 'absolute') {
+ Stack({ alignContent: Alignment.TopStart }) {
+ this.createButtonElement({ instance: $$.instance })
+ }
+ .position({
+ x: $$.left,
+ y: $$.top
+ })
+ } else if ((AttributeManager.getNodeStyle($$.instance._st, 'position') === 'relative')) {
+ Stack({ alignContent: Alignment.TopStart }) {
+ this.createButtonElement({ instance: $$.instance })
+ }
+ .offset({
+ x: $$.left,
+ y: $$.top
+ })
+ } else {
+ this.createButtonElement({ instance: $$.instance })
+ }
+ }
+
+ build() {
+ this.createImageElementWithPosition({
+ instance: this.node,
+ top: AttributeManager.getNodeStyle(this.node._st, 'top', 0),
+ left: AttributeManager.getNodeStyle(this.node._st, 'left', 0),
+ })
+ }
+}
+
+export default TaroButton
diff --git a/packages/taro-platform-harmony/src/components/components-harmony-ets/render.ets b/packages/taro-platform-harmony/src/components/components-harmony-ets/render.ets
index dbd2695ce222..e6614614e000 100644
--- a/packages/taro-platform-harmony/src/components/components-harmony-ets/render.ets
+++ b/packages/taro-platform-harmony/src/components/components-harmony-ets/render.ets
@@ -1,8 +1,12 @@
+import { NodeType } from '@tarojs/runtime'
+
import TaroImage from './image'
import TaroText from './text'
import TaroView from './view'
+import TaroButton from './button'
import TaroScrollView from './scrollView'
+
@Builder
function createNode (node: any) {
if (node.tagName === 'IMAGE') {
@@ -11,6 +15,10 @@ function createNode (node: any) {
TaroText({ node })
} else if (node.tagName === 'SCROLL-VIEW') {
TaroScrollView({ node })
+ } else if (node.tagName === 'BUTTON') {
+ TaroButton({ node })
+ } else if (node.nodeType === NodeType.TEXT_NODE) {
+ TaroText({ node })
} else {
TaroView({ node })
}
diff --git a/packages/taro-platform-harmony/src/components/components-harmony-ets/utils/constant/style.ets b/packages/taro-platform-harmony/src/components/components-harmony-ets/utils/constant/style.ets
index 7bf4fb2f2f5c..d42c651cc08c 100644
--- a/packages/taro-platform-harmony/src/components/components-harmony-ets/utils/constant/style.ets
+++ b/packages/taro-platform-harmony/src/components/components-harmony-ets/utils/constant/style.ets
@@ -6,3 +6,18 @@ export const TEXT_DEFAULT_STYLE = {
FONT_WEIGHT: FontWeight.Normal,
FONT_FAMILY: 'HarmonyOS Sans'
}
+
+export const BUTTON_THEME_COLOR = {
+ default: {
+ text: '#000',
+ background: '#f7f7f7',
+ },
+ primary: {
+ text: '#fff',
+ background: '#1aad19',
+ },
+ warn: {
+ text: '#fff',
+ background: '#e64340'
+ }
+}
diff --git a/packages/taro-platform-harmony/src/runtime-ets/dom/element.ts b/packages/taro-platform-harmony/src/runtime-ets/dom/element.ts
index d363454bbfd6..8b45d1561af5 100644
--- a/packages/taro-platform-harmony/src/runtime-ets/dom/element.ts
+++ b/packages/taro-platform-harmony/src/runtime-ets/dom/element.ts
@@ -106,6 +106,13 @@ class TaroImageElement extends TaroElement {
}
}
+@Observed
+class TaroButtonElement extends TaroElement {
+ constructor() {
+ super('Button')
+ }
+}
+
@Observed
export class FormElement extends TaroElement {
public get type () {
@@ -129,6 +136,7 @@ export class FormElement extends TaroElement {
export {
+ TaroButtonElement,
TaroElement,
TaroImageElement,
TaroTextElement,
diff --git a/packages/taro-vite-runner/src/harmony/page.ts b/packages/taro-vite-runner/src/harmony/page.ts
index c5a46c3c5d61..9e5bfbe89c9e 100644
--- a/packages/taro-vite-runner/src/harmony/page.ts
+++ b/packages/taro-vite-runner/src/harmony/page.ts
@@ -60,6 +60,8 @@ struct Index {
TaroImage({ node: this.node })
} else if (this.node.tagName === 'SCROLL-VIEW') {
TaroScrollView({ node: this.node })
+ } else if (this.node.tagName === 'BUTTON') {
+ TaroButton({ node: this.node })
}
}
}
@@ -75,6 +77,7 @@ struct Index {
'import TaroView from "@tarojs/components/view"',
'import TaroText from "@tarojs/components/text"',
'import TaroImage from "@tarojs/components/image"',
+ 'import TaroButton from "@tarojs/components/button"',
'import TaroScrollView from "@tarojs/components/scrollView"',
'import { TaroElement } from "@tarojs/runtime"',
`import component from "${rawId}"`,
|
441132cab2eac9015318b64a0ba70cc0e05175a0
|
2018-09-13 20:18:51
|
Manjiz
|
test(components-rn): 单元测试:支持Input和Textarea通过属性prop主动变更输入内容
| false
|
单元测试:支持Input和Textarea通过属性prop主动变更输入内容
|
test
|
diff --git a/packages/taro-components-rn/__tests__/input.spec.js b/packages/taro-components-rn/__tests__/input.spec.js
index 9d80db3b50e1..0daabb11d0b3 100644
--- a/packages/taro-components-rn/__tests__/input.spec.js
+++ b/packages/taro-components-rn/__tests__/input.spec.js
@@ -5,16 +5,27 @@ import sinon from 'sinon'
import { Input } from '../src'
describe('<Input /> & <Textarea>', () => {
- it('onKeyDown', () => {
- const spy = sinon.spy()
- const wrapper = shallow(<Input onKeyDown={spy} />)
- wrapper.find(TextInput).props().onKeyPress({ nativeEvent: { key: 'Enter' } })
- expect(spy.calledOnce).toBe(true)
- expect(spy.args[0][0]).toMatchObject({
- which: 13,
- target: expect.objectContaining({
- value: expect.any(String)
+ describe('events', () => {
+ it('onKeyDown', () => {
+ const spy = sinon.spy()
+ const wrapper = shallow(<Input onKeyDown={spy} />)
+ wrapper.find(TextInput).props().onKeyPress({ nativeEvent: { key: 'Enter' } })
+ expect(spy.calledOnce).toBe(true)
+ expect(spy.args[0][0]).toMatchObject({
+ which: 13,
+ target: expect.objectContaining({
+ value: expect.any(String)
+ })
})
})
})
+
+ describe('prop value changed', () => {
+ it('should be new value', () => {
+ const wrapper = shallow(<Input value={'default text'} />)
+ // expect(wrapper.state('returnValue')).toBe('default text')
+ wrapper.setProps({ value: 'new text' })
+ expect(wrapper.state('returnValue')).toBe('new text')
+ })
+ })
})
|
0d738aabde6dbab3a9d05bd86d7352e29e255d88
|
2023-11-02 08:49:20
|
xiaozheng
|
fix: 修改taro-webpack5-runner快照
| false
|
修改taro-webpack5-runner快照
|
fix
|
diff --git a/packages/taro-webpack5-runner/src/__tests__/__snapshots__/config.spec.ts.snap b/packages/taro-webpack5-runner/src/__tests__/__snapshots__/config.spec.ts.snap
index b106944d0bf8..825e321a117d 100644
--- a/packages/taro-webpack5-runner/src/__tests__/__snapshots__/config.spec.ts.snap
+++ b/packages/taro-webpack5-runner/src/__tests__/__snapshots__/config.spec.ts.snap
@@ -14,7 +14,7 @@ require("./vendors");
require("./runtime");
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 143 ], {
- 830: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ 662: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
function mergeReconciler() {}
function mergeInternalComponents() {}
function isArray() {}
@@ -501,7 +501,7 @@ require("./runtime");
};
mergeReconciler(hostConfig);
mergeInternalComponents(components);
- var taro_runtime = __webpack_require__(202);
+ var taro_runtime = __webpack_require__(184);
function setReconciler() {}
function connectReactPage() {}
function createReactApp() {}
@@ -534,11 +534,11 @@ require("./runtime");
function useScope() {}
function initPxTransform() {}
var taro = "taro";
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var app_App = function(_Component) {
(0, inherits.Z)(App, _Component);
var _super = (0, createSuper.Z)(App);
@@ -593,7 +593,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(830);
+ return __webpack_exec__(662);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -1488,7 +1488,7 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 592 ], {
- 800: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 757: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
Component: function() {
@@ -1498,7 +1498,7 @@ require("./runtime");
var Component = {};
__webpack_exports__["default"] = "react-mock";
},
- 202: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 184: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
createReactApp: function() {
@@ -1526,8 +1526,8 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 367 ], {
- 685: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(202);
+ 823: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(184);
Component((0, _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__.createRecursiveComponentConfig)());
}
}, function(__webpack_require__) {
@@ -1535,7 +1535,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 592 ], (function() {
- return __webpack_exec__(685);
+ return __webpack_exec__(823);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -1552,13 +1552,13 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 539 ], {
- 200: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var taro_runtime = __webpack_require__(202);
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ 213: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var taro_runtime = __webpack_require__(184);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var Canvas = {};
var CoverView = {};
var CoverImage = {};
@@ -1614,7 +1614,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(200);
+ return __webpack_exec__(213);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -1677,7 +1677,7 @@ module.exports = {
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 216 ], {
- 177: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 113: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _classCallCheck;
@@ -1689,13 +1689,13 @@ module.exports = {
}
}
},
- 347: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 815: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createClass;
}
});
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _toPrimitive(input, hint) {
if ((0, esm_typeof.Z)(input) !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
@@ -1728,7 +1728,7 @@ module.exports = {
return Constructor;
}
},
- 777: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 605: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createSuper;
@@ -1751,7 +1751,7 @@ module.exports = {
return false;
}
}
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -1780,7 +1780,7 @@ module.exports = {
};
}
},
- 521: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 730: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _inherits;
@@ -1810,7 +1810,7 @@ module.exports = {
if (superClass) _setPrototypeOf(subClass, superClass);
}
},
- 361: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 671: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _typeof;
@@ -1843,7 +1843,7 @@ require("./vendors");
require("./runtime");
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 143 ], {
- 830: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ 662: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
function mergeReconciler() {}
function mergeInternalComponents() {}
function isArray() {}
@@ -2330,7 +2330,7 @@ require("./runtime");
};
mergeReconciler(hostConfig);
mergeInternalComponents(components);
- var taro_runtime = __webpack_require__(202);
+ var taro_runtime = __webpack_require__(184);
function setReconciler() {}
function connectReactPage() {}
function createReactApp() {}
@@ -2363,11 +2363,11 @@ require("./runtime");
function useScope() {}
function initPxTransform() {}
var taro = "taro";
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var app_App = function(_Component) {
(0, inherits.Z)(App, _Component);
var _super = (0, createSuper.Z)(App);
@@ -2422,7 +2422,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(830);
+ return __webpack_exec__(662);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -3157,7 +3157,7 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 592 ], {
- 800: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 757: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
Component: function() {
@@ -3167,7 +3167,7 @@ require("./runtime");
var Component = {};
__webpack_exports__["default"] = "react-mock";
},
- 202: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 184: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
createReactApp: function() {
@@ -3195,8 +3195,8 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 367 ], {
- 685: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(202);
+ 823: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(184);
Component((0, _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__.createRecursiveComponentConfig)());
}
}, function(__webpack_require__) {
@@ -3204,7 +3204,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 592 ], (function() {
- return __webpack_exec__(685);
+ return __webpack_exec__(823);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -3221,13 +3221,13 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 539 ], {
- 200: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var taro_runtime = __webpack_require__(202);
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ 213: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var taro_runtime = __webpack_require__(184);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var Canvas = {};
var CoverView = {};
var CoverImage = {};
@@ -3283,7 +3283,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(200);
+ return __webpack_exec__(213);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -3461,7 +3461,7 @@ module.exports = {
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 216 ], {
- 177: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 113: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _classCallCheck;
@@ -3473,13 +3473,13 @@ module.exports = {
}
}
},
- 347: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 815: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createClass;
}
});
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _toPrimitive(input, hint) {
if ((0, esm_typeof.Z)(input) !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
@@ -3512,7 +3512,7 @@ module.exports = {
return Constructor;
}
},
- 777: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 605: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createSuper;
@@ -3535,7 +3535,7 @@ module.exports = {
return false;
}
}
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -3564,7 +3564,7 @@ module.exports = {
};
}
},
- 521: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 730: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _inherits;
@@ -3594,7 +3594,7 @@ module.exports = {
if (superClass) _setPrototypeOf(subClass, superClass);
}
},
- 361: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 671: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _typeof;
@@ -3783,7 +3783,7 @@ require("./vendors");
require("./runtime");
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 143 ], {
- 830: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ 662: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
function mergeReconciler() {}
function mergeInternalComponents() {}
function isArray() {}
@@ -4270,7 +4270,7 @@ require("./runtime");
};
mergeReconciler(hostConfig);
mergeInternalComponents(components);
- var taro_runtime = __webpack_require__(202);
+ var taro_runtime = __webpack_require__(184);
function setReconciler() {}
function connectReactPage() {}
function createReactApp() {}
@@ -4303,11 +4303,11 @@ require("./runtime");
function useScope() {}
function initPxTransform() {}
var taro = "taro";
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var app_App = function(_Component) {
(0, inherits.Z)(App, _Component);
var _super = (0, createSuper.Z)(App);
@@ -4362,7 +4362,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(830);
+ return __webpack_exec__(662);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -5097,7 +5097,7 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 592 ], {
- 800: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 757: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
Component: function() {
@@ -5107,7 +5107,7 @@ require("./runtime");
var Component = {};
__webpack_exports__["default"] = "react-mock";
},
- 202: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 184: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
createReactApp: function() {
@@ -5135,8 +5135,8 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 367 ], {
- 685: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(202);
+ 823: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(184);
Component((0, _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__.createRecursiveComponentConfig)());
}
}, function(__webpack_require__) {
@@ -5144,7 +5144,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 592 ], (function() {
- return __webpack_exec__(685);
+ return __webpack_exec__(823);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -5165,13 +5165,13 @@ I m irrelevant.
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 539 ], {
- 200: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var taro_runtime = __webpack_require__(202);
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ 213: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var taro_runtime = __webpack_require__(184);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var Canvas = {};
var CoverView = {};
var CoverImage = {};
@@ -5227,7 +5227,7 @@ I m irrelevant.
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(200);
+ return __webpack_exec__(213);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -5290,7 +5290,7 @@ module.exports = {
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 216 ], {
- 177: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 113: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _classCallCheck;
@@ -5302,13 +5302,13 @@ module.exports = {
}
}
},
- 347: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 815: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createClass;
}
});
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _toPrimitive(input, hint) {
if ((0, esm_typeof.Z)(input) !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
@@ -5341,7 +5341,7 @@ module.exports = {
return Constructor;
}
},
- 777: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 605: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createSuper;
@@ -5364,7 +5364,7 @@ module.exports = {
return false;
}
}
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -5393,7 +5393,7 @@ module.exports = {
};
}
},
- 521: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 730: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _inherits;
@@ -5423,7 +5423,7 @@ module.exports = {
if (superClass) _setPrototypeOf(subClass, superClass);
}
},
- 361: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 671: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _typeof;
@@ -5624,7 +5624,7 @@ require("./vendors");
require("./runtime");
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 143 ], {
- 830: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ 662: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
function mergeReconciler() {}
function mergeInternalComponents() {}
function isArray() {}
@@ -6111,7 +6111,7 @@ require("./runtime");
};
mergeReconciler(hostConfig);
mergeInternalComponents(components);
- var taro_runtime = __webpack_require__(202);
+ var taro_runtime = __webpack_require__(184);
function setReconciler() {}
function connectReactPage() {}
function createReactApp() {}
@@ -6144,11 +6144,11 @@ require("./runtime");
function useScope() {}
function initPxTransform() {}
var taro = "taro";
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var app_App = function(_Component) {
(0, inherits.Z)(App, _Component);
var _super = (0, createSuper.Z)(App);
@@ -6203,7 +6203,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(830);
+ return __webpack_exec__(662);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -6938,7 +6938,7 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 592 ], {
- 800: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 757: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
Component: function() {
@@ -6948,7 +6948,7 @@ require("./runtime");
var Component = {};
__webpack_exports__["default"] = "react-mock";
},
- 202: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ 184: function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
createReactApp: function() {
@@ -6976,8 +6976,8 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 367 ], {
- 685: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(202);
+ 823: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(184);
Component((0, _tarojs_runtime__WEBPACK_IMPORTED_MODULE_0__.createRecursiveComponentConfig)());
}
}, function(__webpack_require__) {
@@ -6985,7 +6985,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 592 ], (function() {
- return __webpack_exec__(685);
+ return __webpack_exec__(823);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -7002,13 +7002,13 @@ require("./runtime");
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 539 ], {
- 200: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
- var taro_runtime = __webpack_require__(202);
- var classCallCheck = __webpack_require__(177);
- var createClass = __webpack_require__(347);
- var inherits = __webpack_require__(521);
- var createSuper = __webpack_require__(777);
- var react = __webpack_require__(800);
+ 213: function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) {
+ var taro_runtime = __webpack_require__(184);
+ var classCallCheck = __webpack_require__(113);
+ var createClass = __webpack_require__(815);
+ var inherits = __webpack_require__(730);
+ var createSuper = __webpack_require__(605);
+ var react = __webpack_require__(757);
var Canvas = {};
var CoverView = {};
var CoverImage = {};
@@ -7064,7 +7064,7 @@ require("./runtime");
return __webpack_require__(__webpack_require__.s = moduleId);
};
__webpack_require__.O(0, [ 216, 592 ], (function() {
- return __webpack_exec__(200);
+ return __webpack_exec__(213);
}));
var __webpack_exports__ = __webpack_require__.O();
} ]);
@@ -7127,7 +7127,7 @@ module.exports = {
"use strict";
(wx["webpackJsonp"] = wx["webpackJsonp"] || []).push([ [ 216 ], {
- 177: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 113: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _classCallCheck;
@@ -7139,13 +7139,13 @@ module.exports = {
}
}
},
- 347: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 815: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createClass;
}
});
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _toPrimitive(input, hint) {
if ((0, esm_typeof.Z)(input) !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
@@ -7178,7 +7178,7 @@ module.exports = {
return Constructor;
}
},
- 777: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 605: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _createSuper;
@@ -7201,7 +7201,7 @@ module.exports = {
return false;
}
}
- var esm_typeof = __webpack_require__(361);
+ var esm_typeof = __webpack_require__(671);
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -7230,7 +7230,7 @@ module.exports = {
};
}
},
- 521: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 730: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _inherits;
@@ -7260,7 +7260,7 @@ module.exports = {
if (superClass) _setPrototypeOf(subClass, superClass);
}
},
- 361: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
+ 671: function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
__webpack_require__.d(__webpack_exports__, {
Z: function() {
return _typeof;
|
dd6c7224749e3aa4e75940807f93999dc7dad18d
|
2019-02-14 08:52:09
|
Pamler
|
fix(taro-components): fix richText component (#2131)
| false
|
fix richText component (#2131)
|
fix
|
diff --git a/packages/taro-components/src/components/rich-text/index.js b/packages/taro-components/src/components/rich-text/index.js
index ec71257d653a..8ae522f6c7d8 100644
--- a/packages/taro-components/src/components/rich-text/index.js
+++ b/packages/taro-components/src/components/rich-text/index.js
@@ -17,14 +17,19 @@ class RichText extends Nerv.Component {
style: ''
}
if (item.hasOwnProperty('attrs')) {
- obj.className = item.attrs.class || ''
- obj.style = item.attrs.style || ''
+ for (const key in item.attrs) {
+ if (key === 'class') {
+ obj.className = item.attrs[key] || ''
+ } else {
+ obj[key] = item.attrs[key] || ''
+ }
+ }
}
return Nerv.createElement(item.name, obj, child)
}
}
- renderChildrens (arr) {
+ renderChildrens (arr = []) {
if (arr.length === 0) return
return arr.map((list, i) => {
if (list.type === 'text') {
|
02559f9d51d396148b470e772653dfa0843e47ac
|
2020-09-22 17:20:42
|
ZakaryCode
|
fix(components): remove unnecessary assignment
| false
|
remove unnecessary assignment
|
fix
|
diff --git a/packages/taro-components/src/components/image/image.tsx b/packages/taro-components/src/components/image/image.tsx
index d245fe7a47b6..176977b85ee9 100644
--- a/packages/taro-components/src/components/image/image.tsx
+++ b/packages/taro-components/src/components/image/image.tsx
@@ -77,7 +77,7 @@ export class Image implements ComponentInterface {
render () {
const {
src,
- mode = 'scaleToFill',
+ mode,
lazyLoad,
aspectFillMode,
imageOnLoad,
|
End of preview. Expand
in Data Studio
No dataset card yet
- Downloads last month
- 2