From d5bd0a3702939b3266db196e2274d7cb3124319d Mon Sep 17 00:00:00 2001 From: Wing Gao Date: Wed, 15 Aug 2018 19:44:31 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[TS]=20=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?import=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mp-compiler/parse-ts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mp-compiler/parse-ts.js b/lib/mp-compiler/parse-ts.js index 44acaf4..8b42334 100644 --- a/lib/mp-compiler/parse-ts.js +++ b/lib/mp-compiler/parse-ts.js @@ -57,7 +57,7 @@ function delint (sourceFile) { switch (node.kind) { case ts.SyntaxKind.ImportDeclaration: // 只处理 import Comp from 'xxx.vue' - if (node.importClause.name) { + if (node.importClause && node.importClause.name) { importsMap[node.importClause.name.escapedText] = node.moduleSpecifier.text } // report(node, 'import') From b0eea21cc8125ab51afe5013337df7a14f08b9b4 Mon Sep 17 00:00:00 2001 From: F-loat Date: Sun, 22 Jul 2018 23:54:48 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20#562=20=E6=B7=BB=E5=8A=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=20script=20=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/loader.js | 8 ++++++-- lib/mp-compiler/util.js | 27 ++++++++++++++------------- lib/selector.js | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index c4d00c3..35f85c1 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -24,7 +24,7 @@ var hasBuble = !!tryRequire('buble-loader') // for mp js var { compileMP, compileMPScript } = require('./mp-compiler') -var { defaultStylePart } = require('./mp-compiler/util') +var { defaultPart } = require('./mp-compiler/util') var rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/ @@ -103,7 +103,11 @@ module.exports = function (content) { // fix #153: 根组件没有 style 模块,不生成页面的 wxss,补齐内容方便加载 vendor.wxss if (!parts.styles.length) { - parts.styles.push(defaultStylePart) + parts.styles.push(defaultPart('style')) + } + // fix #562: 组件没有 script 模块,会阻塞编译 + if (!parts.script) { + parts.script = defaultPart('script') } var hasScoped = parts.styles.some(function (s) { return s.scoped }) diff --git a/lib/mp-compiler/util.js b/lib/mp-compiler/util.js index 26aa5b1..27726f5 100644 --- a/lib/mp-compiler/util.js +++ b/lib/mp-compiler/util.js @@ -121,23 +121,24 @@ function getBabelrc (src) { return '' } -const defaultStylePart = { - type: 'style', - content: '\n', - start: 0, - attrs: {}, - end: 1, - map: { - version: 3, - sources: [], - names: [], - mappings: '', - sourcesContent: [] +const defaultPart = type => { + return { + type, + content: '\n', + start: 0, + attrs: {}, + end: 1, + map: { + version: 3, + sources: [], + names: [], + mappings: '', + sourcesContent: [] } } module.exports = { - defaultStylePart, + defaultPart, cacheFileInfo, getFileInfo, getCompNameAndSrc, diff --git a/lib/selector.js b/lib/selector.js index facb9e0..aa21182 100644 --- a/lib/selector.js +++ b/lib/selector.js @@ -5,7 +5,7 @@ var path = require('path') var parse = require('./parser') var loaderUtils = require('loader-utils') -var { defaultStylePart } = require('./mp-compiler/util') +var { defaultPart } = require('./mp-compiler/util') module.exports = function (content) { this.cacheable() @@ -17,6 +17,6 @@ module.exports = function (content) { if (Array.isArray(part)) { part = part[query.index] } - part = part || defaultStylePart + part = part || defaultPart('style') this.callback(null, part.content, part.map) } From 0ddd768e60a377a46667ddce42aa0aeb221fa878 Mon Sep 17 00:00:00 2001 From: Wing Gao Date: Wed, 15 Aug 2018 19:44:31 +0800 Subject: [PATCH 3/5] =?UTF-8?q?[TS]=20=E4=BF=AE=E5=A4=8D=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?import=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/mp-compiler/parse-ts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mp-compiler/parse-ts.js b/lib/mp-compiler/parse-ts.js index 44acaf4..8b42334 100644 --- a/lib/mp-compiler/parse-ts.js +++ b/lib/mp-compiler/parse-ts.js @@ -57,7 +57,7 @@ function delint (sourceFile) { switch (node.kind) { case ts.SyntaxKind.ImportDeclaration: // 只处理 import Comp from 'xxx.vue' - if (node.importClause.name) { + if (node.importClause && node.importClause.name) { importsMap[node.importClause.name.escapedText] = node.moduleSpecifier.text } // report(node, 'import') From c996e6d4e85b7d6ee0f4ef79d86ad4e68d531eea Mon Sep 17 00:00:00 2001 From: F-loat Date: Sun, 22 Jul 2018 23:54:48 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20#562=20=E6=B7=BB=E5=8A=A0=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=20script=20=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/loader.js | 8 ++++++-- lib/mp-compiler/util.js | 27 ++++++++++++++------------- lib/selector.js | 4 ++-- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index c4d00c3..35f85c1 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -24,7 +24,7 @@ var hasBuble = !!tryRequire('buble-loader') // for mp js var { compileMP, compileMPScript } = require('./mp-compiler') -var { defaultStylePart } = require('./mp-compiler/util') +var { defaultPart } = require('./mp-compiler/util') var rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/ @@ -103,7 +103,11 @@ module.exports = function (content) { // fix #153: 根组件没有 style 模块,不生成页面的 wxss,补齐内容方便加载 vendor.wxss if (!parts.styles.length) { - parts.styles.push(defaultStylePart) + parts.styles.push(defaultPart('style')) + } + // fix #562: 组件没有 script 模块,会阻塞编译 + if (!parts.script) { + parts.script = defaultPart('script') } var hasScoped = parts.styles.some(function (s) { return s.scoped }) diff --git a/lib/mp-compiler/util.js b/lib/mp-compiler/util.js index 26aa5b1..27726f5 100644 --- a/lib/mp-compiler/util.js +++ b/lib/mp-compiler/util.js @@ -121,23 +121,24 @@ function getBabelrc (src) { return '' } -const defaultStylePart = { - type: 'style', - content: '\n', - start: 0, - attrs: {}, - end: 1, - map: { - version: 3, - sources: [], - names: [], - mappings: '', - sourcesContent: [] +const defaultPart = type => { + return { + type, + content: '\n', + start: 0, + attrs: {}, + end: 1, + map: { + version: 3, + sources: [], + names: [], + mappings: '', + sourcesContent: [] } } module.exports = { - defaultStylePart, + defaultPart, cacheFileInfo, getFileInfo, getCompNameAndSrc, diff --git a/lib/selector.js b/lib/selector.js index facb9e0..aa21182 100644 --- a/lib/selector.js +++ b/lib/selector.js @@ -5,7 +5,7 @@ var path = require('path') var parse = require('./parser') var loaderUtils = require('loader-utils') -var { defaultStylePart } = require('./mp-compiler/util') +var { defaultPart } = require('./mp-compiler/util') module.exports = function (content) { this.cacheable() @@ -17,6 +17,6 @@ module.exports = function (content) { if (Array.isArray(part)) { part = part[query.index] } - part = part || defaultStylePart + part = part || defaultPart('style') this.callback(null, part.content, part.map) } From e8e70802da0f49ee1a57a880cfbdc1ee1d18544c Mon Sep 17 00:00:00 2001 From: anchengjian Date: Mon, 20 Aug 2018 01:05:10 +0800 Subject: [PATCH 5/5] new version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ff45960..bb1c8ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mpvue-loader", - "version": "1.1.2", + "version": "1.1.3", "description": "mpvue single-file component loader for Webpack", "main": "index.js", "repository": {