From e7bc62b90a814dbee488cf498215e7b2bf0550d6 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 3 Jan 2020 18:01:14 +0800 Subject: [PATCH] feat: add optionalChaining --- packages/uni-cli-shared/lib/platform.js | 19 +++++++++++++++++-- .../webpack-uni-mp-loader/lib/main-new.js | 19 +++++++------------ .../webpack-uni-mp-loader/lib/script-new.js | 15 +++++---------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/uni-cli-shared/lib/platform.js b/packages/uni-cli-shared/lib/platform.js index c165ee5a1..ce9098424 100644 --- a/packages/uni-cli-shared/lib/platform.js +++ b/packages/uni-cli-shared/lib/platform.js @@ -123,7 +123,9 @@ const PLATFORMS = { } = getH5Options() const to = path.join(assetsDir, `[name].${VUE_APP_INDEX_CSS_HASH}.[ext]`) if (process.env.NODE_ENV === 'production') { - const templateContent = fs.readFileSync(template, { encoding: 'utf8' }) + const templateContent = fs.readFileSync(template, { + encoding: 'utf8' + }) if (/\bVUE_APP_INDEX_CSS_HASH\b/.test(templateContent)) { indexCssCopyOptions[0].to = to } @@ -584,5 +586,18 @@ module.exports = { }, getPlatformSass () { return SASS + }, + getBabelParserOptions () { + return { + sourceType: 'module', + plugins: [ + 'optionalChaining', + 'typescript', + ['decorators', { + decoratorsBeforeExport: true + }], + 'classProperties' + ] + } } -} +} diff --git a/packages/webpack-uni-mp-loader/lib/main-new.js b/packages/webpack-uni-mp-loader/lib/main-new.js index 36545b8a6..e6710378f 100644 --- a/packages/webpack-uni-mp-loader/lib/main-new.js +++ b/packages/webpack-uni-mp-loader/lib/main-new.js @@ -13,6 +13,10 @@ const { jsPreprocessOptions } = require('@dcloudio/uni-cli-shared') +const { + getBabelParserOptions +} = require('@dcloudio/uni-cli-shared/lib/platform') + const { updateUsingComponents } = require('@dcloudio/uni-cli-shared/lib/cache') @@ -55,14 +59,14 @@ module.exports = function (content) { const vuePagePath = path.resolve(process.env.UNI_INPUT_DIR, normalizePath(params.page) + '.vue') if (!fs.existsSync(vuePagePath)) { const nvuePagePath = path.resolve(process.env.UNI_INPUT_DIR, normalizePath(params.page) + - '.nvue') + '.nvue') if (fs.existsSync(nvuePagePath)) { ext = '.nvue' } } } return ` -import Vue from 'vue' +import Vue from 'vue' import Page from './${normalizePath(params.page)}${ext}' createPage(Page) ` @@ -78,16 +82,7 @@ createPage(Page) state: { components } - } = traverse(parser.parse(content, { - sourceType: 'module', - plugins: [ - 'typescript', - ['decorators', { - decoratorsBeforeExport: true - }], - 'classProperties' - ] - }), { + } = traverse(parser.parse(content, getBabelParserOptions()), { components: [] }) diff --git a/packages/webpack-uni-mp-loader/lib/script-new.js b/packages/webpack-uni-mp-loader/lib/script-new.js index 802ecb5f7..73cd147d0 100644 --- a/packages/webpack-uni-mp-loader/lib/script-new.js +++ b/packages/webpack-uni-mp-loader/lib/script-new.js @@ -10,6 +10,10 @@ const { jsPreprocessOptions } = require('@dcloudio/uni-cli-shared') +const { + getBabelParserOptions +} = require('@dcloudio/uni-cli-shared/lib/platform') + const { updateUsingComponents } = require('@dcloudio/uni-cli-shared/lib/cache') @@ -63,16 +67,7 @@ module.exports = function (content, map) { state: { components } - } = traverse(parser.parse(content, { - sourceType: 'module', - plugins: [ - 'typescript', - ['decorators', { - decoratorsBeforeExport: true - }], - 'classProperties' - ] - }), { + } = traverse(parser.parse(content, getBabelParserOptions()), { type, components: [] }) -- GitLab