Skip to content

Commit

Permalink
style: eslint style fixs part II
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaufy committed Oct 20, 2019
1 parent 34a22f6 commit 0ff522c
Show file tree
Hide file tree
Showing 61 changed files with 90 additions and 165 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"no-new-func": 0
},
"globals": {
__VERSION,
App,
Page,
wx,
__VERSION__,
Component
},
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
Expand Down
1 change: 0 additions & 1 deletion packages/cli/core/plugins/parser/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
const sfcCompiler = require('vue-template-compiler');
const fs = require('fs');
const path = require('path');
const CONST = require('../../util/const');
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/core/plugins/parser/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ exports = module.exports = function() {
// e.g.
// plugins://appid/xxxdfdf
// module:some-3rd-party-component
let matchs = url.match(/([^:]+)\:(.+)/);
let matchs = url.match(/([^:]+):(.+)/);
let request = url;

if (matchs) {
Expand Down Expand Up @@ -130,6 +130,7 @@ exports = module.exports = function() {
});
});

// eslint-disable-next-line
this.register('wepy-parser-config-component-raw', function(name, prefix, source, target, ctx) {
return Promise.resolve({
name,
Expand All @@ -139,8 +140,6 @@ exports = module.exports = function() {

this.register('wepy-parser-config-component-module', function(name, prefix, source, target, ctx) {
let contextDir = path.dirname(ctx.file);
let modulePath = this.resolvers.normal.resolveSync({}, contextDir, source);

return this.resolvers.normal.resolve({}, contextDir, source, {}).then(resolved => {
return {
name: name,
Expand All @@ -156,8 +155,6 @@ exports = module.exports = function() {
const moduleRequest = loaderUtils.urlToRequest(source, source.charAt(0) === '/' ? '' : null);

let contextDir = path.dirname(ctx.file);
let resolvedPath = this.resolvers.normal.resolveSync({}, contextDir, moduleRequest);
let relativePath = path.relative(contextDir, resolvedPath);

return this.resolvers.normal.resolve({}, contextDir, moduleRequest, {}).then(resolved => {
return {
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/core/plugins/parser/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/
const fs = require('fs');
const path = require('path');
const loaderUtils = require('loader-utils');

const hashUtil = require('../../util/hash');

Expand Down Expand Up @@ -81,7 +80,6 @@ exports = module.exports = function() {
);
throw new Error('EXIT');
} else {
console.log(node);
this.hookUnique(
'error-handler',
'script',
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/core/plugins/parser/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
const sfcCompiler = require('vue-template-compiler');
const fs = require('fs');
const path = require('path');

const acorn = require('acorn-dynamic-import').default;
const hashUtil = require('../../util/hash');
const Walker = require('../../ast/walker');
const toAst = require('../../ast/toAST');
Expand Down Expand Up @@ -91,7 +89,7 @@ exports = module.exports = function() {

let depTasks = walker.deps.map(dep => this.hookUnique('wepy-parser-dep', node, ctx, dep));

return Promise.all(depTasks).then(rst => {
return Promise.all(depTasks).then(() => {
return node.parsed;
});
} else {
Expand Down
1 change: 0 additions & 1 deletion packages/cli/core/plugins/parser/template.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const xmllint = require('../../util/xmllint');
const errorHandler = require('../../util/error');

exports = module.exports = function() {
this.register('wepy-parser-template', function(node, ctx) {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/core/plugins/parser/wpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ exports = module.exports = function() {
return this.applyCompiler(context.sfc.template, context);
}
})
.then(parsed => {
.then(() => {
if (sfc.script) {
sfc.script.lang = sfc.script.lang || 'babel';
return this.applyCompiler(context.sfc.script, context);
Expand All @@ -107,7 +107,7 @@ exports = module.exports = function() {
);
}
})
.then((all = []) => {
.then(() => {
context.done = true;
return context;
});
Expand All @@ -128,7 +128,7 @@ exports = module.exports = function() {
// wxs is an array.
let nodes = [].concat(sfc[type]);
nodes.forEach(node => {
src = node ? node.src : '';
const src = node ? node.src : '';
if (src) {
const request = loaderUtils.urlToRequest(src, src.charAt(0) === '/' ? '' : null);
tasks.push(
Expand Down
3 changes: 0 additions & 3 deletions packages/cli/core/plugins/scriptDepFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ exports = module.exports = function() {
* S4: import 'xxxx' from 'xxx';j
*/
this.register('script-dep-fix', function scriptDepFix(parsed, isNPM) {
let code = parsed.code;
let fixPos = 0;

if (!parsed.fixedDeps) {
parsed.fixedDeps = [];
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/core/plugins/scriptInjection.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ exports = module.exports = function() {
}

// avoid to import duplicated
// eslint-disable-next-line
if (source.relIndex != null) {
const idx = source.replacements.findIndex(arr => {
return arr[arr.length - 1] === source.relIndex;
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/core/plugins/template/attrs/bindClass.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const parseClass = require('../../../ast/parseClass');

exports = module.exports = function() {
this.register('template-parse-ast-attr-:class', function parseBindClass({ item, name, expr }) {
this.register('template-parse-ast-attr-:class', function parseBindClass({ item, expr }) {
let exprArray = parseClass(expr);
let bindClass = [];
exprArray.forEach(item => {
if (typeof item === 'string') {
bindClass.push(`${item}`);
} else {
Object.keys(item).forEach(name => {
// eslint-disable-next-line
let exp = item[name].replace(/\'/gi, '\\\'').replace(/\"/gi, '\\"');
// eslint-disable-next-line
name = name.replace(/\'/gi, '\\\'').replace(/\"/gi, '\\"');
bindClass.push(`${exp} ? '${name}' : ''`);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/core/plugins/template/attrs/bindStyle.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const exprParser = require('../../../util/exprParser');

exports = module.exports = function() {
this.register('template-parse-ast-attr-:style', function parseBindStyle({ item, name, expr }) {
this.register('template-parse-ast-attr-:style', function parseBindStyle({ item, expr }) {
let exprObj = exprParser.str2obj(expr);
item.bindStyle = Object.keys(exprObj).map(name => {
// eslint-disable-next-line
let exp = exprObj[name].replace(/\'/gi, '\\\'').replace(/\"/gi, '\\"');

// add brackets to fix priority of "+" operator.
if (/^\(.*\)$/.test(exp) === false) {
exp = `(${exp})`;
}
// eslint-disable-next-line
name = name.replace(/\'/gi, '\\\'').replace(/\"/gi, '\\"');
name = exprParser.hyphenate(name);
return `'${name}:' + ${exp} + ';'`;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/core/plugins/template/attrs/ref.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports = module.exports = function() {
this.register('template-parse-ast-attr-ref', function parseRef({ item, name, expr }) {
this.register('template-parse-ast-attr-ref', function parseRef({ expr }) {
return {
attrs: {
'data-ref': `${expr}`
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/core/plugins/template/attrs/src.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ exports = module.exports = function() {
return parsed;
});

this.register('template-parse-ast-attr-src', function parseAssetUrl({ item, name, expr, ctx }) {
this.register('template-parse-ast-attr-src', function parseAssetUrl({ expr, ctx }) {
let parsed = this.hookUnique('url-to-module', expr);

if (parsed.isModule) {
Expand All @@ -47,7 +47,6 @@ exports = module.exports = function() {
parser: {},
code: code,
encoding,
encoding,
source: source,
depModules: null,
type: type
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/core/plugins/template/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ const MODEL_MAP = {
'radio-group': {
type: 'change',
value: null
},
picker: {
type: 'change',
value: 'value'
}
};

Expand Down Expand Up @@ -191,7 +187,7 @@ function generateModelFunctionInScope(scope, iterators, expr) {
exports = module.exports = function() {
let modelid = 0;

this.register('template-parse-ast-attr-v-model', function parseVModel({ item, name, expr, modifiers, scope, ctx }) {
this.register('template-parse-ast-attr-v-model', function parseVModel({ item, expr, scope }) {
let attrs = item.attribs;

let conflicts = ['value', 'v-bind', ':value'].filter(v => !!attrs[v]);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/core/plugins/template/directives/v-on.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const parseHandlerProxy = (expr, scope) => {
let eventInArg = false;

let parsedHandler;
// eslint-disable-next-line
if (/^[\w\.]+$/.test(expr)) {
// @tap="doSomething" or @tap="m.doSomething"
eventInArg = true;
Expand Down Expand Up @@ -69,7 +70,6 @@ const parseHandlerProxy = (expr, scope) => {
* @return {Object} parse result, e.g. {type: "bind:tap", name: "doSomething", params: ["item"]}
*/
const parseHandler = (name = '', value = '', scope) => {
let handler = '';
let type = '';
let info;
info = parseHandlerProxy(value, scope);
Expand Down
82 changes: 2 additions & 80 deletions packages/cli/core/plugins/template/parse.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const htmlparser = require('htmlparser2');
const tools = require('../../util/tools');
const onRE = /^@|^v-on:/;
const bindRE = /^:|^v-bind:/;
const modifierRE = /\.[^.]+/g;

const nativeBindRE = /^bind:?|^catch:?|^capture-bind:?|^capture-catch:?/;

const toAST = html => {
return new Promise((resolve, reject) => {
const handler = new htmlparser.DomHandler(
Expand Down Expand Up @@ -43,7 +39,6 @@ exports = module.exports = function() {
this.register('template-parse-ast-attr', function parseAstAttr(item, scope, rel, ctx) {
let attrs = item.attribs;
let parsedAttr = item.parsedAttr || {};
let isComponent = !!rel.components[item.name];
let parsed = null;

let cleanAttrs = [];
Expand Down Expand Up @@ -107,80 +102,6 @@ exports = module.exports = function() {
item.parsedAttr = parsedAttr;

return [item, scope, rel, ctx];
/* REMOVE LATER
for (let name in attrs) {
let expr = attrs[name];
({ item, name, expr } = this.hookUniqueReturnArg('template-parse-ast-pre-attr-' + name, { item, name, expr }));
let modifiers = parseModifiers(name);
if (modifiers) {
name = name.replace(modifierRE, '');
}
parsed = this.hookUnique('template-parse-ast-attr-' + name, { item, name, expr, modifiers, scope, ctx });
if (parsed && parsed.scope) {
scope = parsed.scope;
}
let applyHook = `template-parse-ast-attr-${name}-apply`;
if (this.hasHook(applyHook)) {
this.hookUnique('template-parse-ast-attr-' + name + '-apply', { parsed, attrs: parsedAttr, rel });
continue;
}
if (nativeBindRE.test(name)) {
let bindType = name.match(nativeBindRE)[0];
name = name.replace(bindType, '');
modifiers = {};
if (bindType[bindType.length - 1] === ':') {
bindType = bindType.substring(0, bindType.length - 1);
}
switch (bindType) {
case 'bind':
break;
case 'catch':
modifiers.stop = true;
break;
case 'capture-bind':
modifiers.capture = true;
break;
case 'capture-catch':
modifiers.stop = true;
modifiers.capture = true;
break;
}
let parsedNativeBind = this.hookUnique('template-parse-ast-attr-v-on', item, name, expr, modifiers, scope);
this.hookUnique('template-parse-ast-attr-v-on-apply', { parsed: parsedNativeBind, attrs: parsedAttr, rel });
} else if (bindRE.test(name)) { // :prop or v-bind:prop;
let parsedBind = this.hookUnique('template-parse-ast-attr-v-bind', item, name, expr, modifiers, scope);
if (isComponent) { // It's a prop
parsedAttr[parsedBind.prop] = parsedBind.expr;
} else {
// TODO:
}
} else if (onRE.test(name)) { // @ or v-on:
let parsedOn = this.hookUnique('template-parse-ast-attr-v-on', item, name.replace(onRE, ''), expr, modifiers, scope);
this.hookUnique('template-parse-ast-attr-v-on-apply', { parsed: parsedOn, attrs: parsedAttr, rel });
continue;
} else {
if (parsed) {
parsedAttr = Object.assign(parsedAttr, parsed.attrs);
} else {
parsedAttr[name] = expr;
}
}
}
item.parsedAttr = parsedAttr;
return [item, scope, rel];
*/
});

this.register('template-parse-ast-tag', function parseAstTag(item, rel) {
Expand Down Expand Up @@ -289,8 +210,9 @@ exports = module.exports = function() {
this.register('template-parse', function parse(html, components, ctx) {
return toAST(html).then(ast => {
let rel = { handlers: {}, components: components, on: {} };
let scope = null;

// eslint-disable-next-line
let scope = null;
[ast, scope, rel] = this.hookSeq('template-parse-ast', ast, null, rel, ctx);

let code = this.hookUnique('template-parse-ast-to-str', ast);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/core/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ exports = module.exports = function ast(source) {
}

if (!ast || typeof ast !== 'object') {
throw new Error(`Source could\'t be parsed`);
throw new Error(`Source could't be parsed`);
}
return ast;
};
2 changes: 2 additions & 0 deletions packages/cli/core/util/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports = module.exports = {
const result = codeFrameColumns(codeFrame, location, {
/* options */
});
// eslint-disable-next-line
console.log(result);
},
error(msg, file, codeFrame, location) {
Expand All @@ -16,6 +17,7 @@ exports = module.exports = {
const result = codeFrameColumns(codeFrame, location, {
/* options */
});
// eslint-disable-next-line
console.log(result);
process.exit();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/core/util/exprParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ exports = module.exports = {
result = {},
str = '';
for (i = 0; i < len; i++) {
// eslint-disable-next-line
if (exp[i] === '\'' || exp[i] === '"') {
if (flagStack.length && flagStack[0] === exp[i]) {
flagStack.pop();
Expand Down Expand Up @@ -88,7 +89,7 @@ exports = module.exports = {
}
return result;
} else {
throw ':class expression is not correct, it has to be {\'className\': mycondition}';
throw `:class expression is not correct, it has to be {'className': mycondition}`;
}
})
};
Loading

0 comments on commit 0ff522c

Please sign in to comment.