mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-29 03:45:15 +00:00
119 lines
13 KiB
JavaScript
119 lines
13 KiB
JavaScript
'use strict';var _vm = require('vm');var _vm2 = _interopRequireDefault(_vm);
|
|
var _docsUrl = require('../docsUrl');var _docsUrl2 = _interopRequireDefault(_docsUrl);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { 'default': obj };}
|
|
|
|
module.exports = {
|
|
meta: {
|
|
type: 'suggestion',
|
|
docs: {
|
|
url: (0, _docsUrl2['default'])('dynamic-import-chunkname') },
|
|
|
|
schema: [{
|
|
type: 'object',
|
|
properties: {
|
|
importFunctions: {
|
|
type: 'array',
|
|
uniqueItems: true,
|
|
items: {
|
|
type: 'string' } },
|
|
|
|
|
|
webpackChunknameFormat: {
|
|
type: 'string' } } }] },
|
|
|
|
|
|
|
|
|
|
|
|
create: function () {function create(context) {
|
|
var config = context.options[0];var _ref =
|
|
config || {},_ref$importFunctions = _ref.importFunctions,importFunctions = _ref$importFunctions === undefined ? [] : _ref$importFunctions;var _ref2 =
|
|
config || {},_ref2$webpackChunknam = _ref2.webpackChunknameFormat,webpackChunknameFormat = _ref2$webpackChunknam === undefined ? '[0-9a-zA-Z-_/.]+' : _ref2$webpackChunknam;
|
|
|
|
var paddedCommentRegex = /^ (\S[\s\S]+\S) $/;
|
|
var commentStyleRegex = /^( \w+: (["'][^"']*["']|\d+|false|true),?)+ $/;
|
|
var chunkSubstrFormat = ' webpackChunkName: ["\']' + String(webpackChunknameFormat) + '["\'],? ';
|
|
var chunkSubstrRegex = new RegExp(chunkSubstrFormat);
|
|
|
|
function run(node, arg) {
|
|
var sourceCode = context.getSourceCode();
|
|
var leadingComments = sourceCode.getCommentsBefore ?
|
|
sourceCode.getCommentsBefore(arg) // This method is available in ESLint >= 4.
|
|
: sourceCode.getComments(arg).leading; // This method is deprecated in ESLint 7.
|
|
|
|
if (!leadingComments || leadingComments.length === 0) {
|
|
context.report({
|
|
node: node,
|
|
message: 'dynamic imports require a leading comment with the webpack chunkname' });
|
|
|
|
return;
|
|
}
|
|
|
|
var isChunknamePresent = false;var _iteratorNormalCompletion = true;var _didIteratorError = false;var _iteratorError = undefined;try {
|
|
|
|
for (var _iterator = leadingComments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {var comment = _step.value;
|
|
if (comment.type !== 'Block') {
|
|
context.report({
|
|
node: node,
|
|
message: 'dynamic imports require a /* foo */ style comment, not a // foo comment' });
|
|
|
|
return;
|
|
}
|
|
|
|
if (!paddedCommentRegex.test(comment.value)) {
|
|
context.report({
|
|
node: node,
|
|
message: 'dynamic imports require a block comment padded with spaces - /* foo */' });
|
|
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// just like webpack itself does
|
|
_vm2['default'].runInNewContext('(function(){return {' + String(comment.value) + '}})()');
|
|
}
|
|
catch (error) {
|
|
context.report({
|
|
node: node,
|
|
message: 'dynamic imports require a "webpack" comment with valid syntax' });
|
|
|
|
return;
|
|
}
|
|
|
|
if (!commentStyleRegex.test(comment.value)) {
|
|
context.report({
|
|
node: node,
|
|
message: 'dynamic imports require a leading comment in the form /*' +
|
|
chunkSubstrFormat + '*/' });
|
|
|
|
return;
|
|
}
|
|
|
|
if (chunkSubstrRegex.test(comment.value)) {
|
|
isChunknamePresent = true;
|
|
}
|
|
}} catch (err) {_didIteratorError = true;_iteratorError = err;} finally {try {if (!_iteratorNormalCompletion && _iterator['return']) {_iterator['return']();}} finally {if (_didIteratorError) {throw _iteratorError;}}}
|
|
|
|
if (!isChunknamePresent) {
|
|
context.report({
|
|
node: node,
|
|
message: 'dynamic imports require a leading comment in the form /*' +
|
|
chunkSubstrFormat + '*/' });
|
|
|
|
}
|
|
}
|
|
|
|
return {
|
|
ImportExpression: function () {function ImportExpression(node) {
|
|
run(node, node.source);
|
|
}return ImportExpression;}(),
|
|
|
|
CallExpression: function () {function CallExpression(node) {
|
|
if (node.callee.type !== 'Import' && importFunctions.indexOf(node.callee.name) < 0) {
|
|
return;
|
|
}
|
|
|
|
run(node, node.arguments[0]);
|
|
}return CallExpression;}() };
|
|
|
|
}return create;}() };
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ydWxlcy9keW5hbWljLWltcG9ydC1jaHVua25hbWUuanMiXSwibmFtZXMiOlsibW9kdWxlIiwiZXhwb3J0cyIsIm1ldGEiLCJ0eXBlIiwiZG9jcyIsInVybCIsInNjaGVtYSIsInByb3BlcnRpZXMiLCJpbXBvcnRGdW5jdGlvbnMiLCJ1bmlxdWVJdGVtcyIsIml0ZW1zIiwid2VicGFja0NodW5rbmFtZUZvcm1hdCIsImNyZWF0ZSIsImNvbnRleHQiLCJjb25maWciLCJvcHRpb25zIiwicGFkZGVkQ29tbWVudFJlZ2V4IiwiY29tbWVudFN0eWxlUmVnZXgiLCJjaHVua1N1YnN0ckZvcm1hdCIsImNodW5rU3Vic3RyUmVnZXgiLCJSZWdFeHAiLCJydW4iLCJub2RlIiwiYXJnIiwic291cmNlQ29kZSIsImdldFNvdXJjZUNvZGUiLCJsZWFkaW5nQ29tbWVudHMiLCJnZXRDb21tZW50c0JlZm9yZSIsImdldENvbW1lbnRzIiwibGVhZGluZyIsImxlbmd0aCIsInJlcG9ydCIsIm1lc3NhZ2UiLCJpc0NodW5rbmFtZVByZXNlbnQiLCJjb21tZW50IiwidGVzdCIsInZhbHVlIiwidm0iLCJydW5Jbk5ld0NvbnRleHQiLCJlcnJvciIsIkltcG9ydEV4cHJlc3Npb24iLCJzb3VyY2UiLCJDYWxsRXhwcmVzc2lvbiIsImNhbGxlZSIsImluZGV4T2YiLCJuYW1lIiwiYXJndW1lbnRzIl0sIm1hcHBpbmdzIjoiYUFBQSx3QjtBQUNBLHFDOztBQUVBQSxPQUFPQyxPQUFQLEdBQWlCO0FBQ2ZDLFFBQU07QUFDSkMsVUFBTSxZQURGO0FBRUpDLFV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WdleC50ZXN0KGNvbW1lbnQudmFsdWUpKSB7XG4gICAgICAgICAgY29udGV4dC5yZXBvcnQoe1xuICAgICAgICAgICAgbm9kZSxcbiAgICAgICAgICAgIG1lc3NhZ2U6IGBkeW5hbWljIGltcG9ydHMgcmVxdWlyZSBhIGJsb2NrIGNvbW1lbnQgcGFkZGVkIHdpdGggc3BhY2VzIC0gLyogZm9vICovYCxcbiAgICAgICAgICB9KTtcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICB0cnkge1xuICAgICAgICAgIC8vIGp1c3QgbGlrZSB3ZWJwYWNrIGl0c2VsZiBkb2VzXG4gICAgICAgICAgdm0ucnVuSW5OZXdDb250ZXh0KGAoZnVuY3Rpb24oKXtyZXR1cm4geyR7Y29tbWVudC52YWx1ZX19fSkoKWApO1xuICAgICAgICB9XG4gICAgICAgIGNhdGNoIChlcnJvcikge1xuICAgICAgICAgIGNvbnRleHQucmVwb3J0KHtcbiAgICAgICAgICAgIG5vZGUsXG4gICAgICAgICAgICBtZXNzYWdlOiBgZHluYW1pYyBpbXBvcnRzIHJlcXVpcmUgYSBcIndlYnBhY2tcIiBjb21tZW50IHdpdGggdmFsaWQgc3ludGF4YCxcbiAgICAgICAgICB9KTtcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBpZiAoIWNvbW1lbnRTdHlsZVJlZ2V4LnRlc3QoY29tbWVudC52YWx1ZSkpIHtcbiAgICAgICAgICBjb250ZXh0LnJlcG9ydCh7XG4gICAgICAgICAgICBub2RlLFxuICAgICAgICAgICAgbWVzc2FnZTpcbiAgICAgICAgICAgICAgYGR5bmFtaWMgaW1wb3J0cyByZXF1aXJlIGEgbGVhZGluZyBjb21tZW50IGluIHRoZSBmb3JtIC8qJHtjaHVua1N1YnN0ckZvcm1hdH0qL2AsXG4gICAgICAgICAgfSk7XG4gICAgICAgICAgcmV0dXJuO1xuICAgICAgICB9XG5cbiAgICAgICAgaWYgKGNodW5rU3Vic3RyUmVnZXgudGVzdChjb21tZW50LnZhbHVlKSkge1xuICAgICAgICAgIGlzQ2h1bmtuYW1lUHJlc2VudCA9IHRydWU7XG4gICAgICAgIH1cbiAgICAgIH1cblxuICAgICAgaWYgKCFpc0NodW5rbmFtZVByZXNlbnQpIHtcbiAgICAgICAgY29udGV4dC5yZXBvcnQoe1xuICAgICAgICAgIG5vZGUsXG4gICAgICAgICAgbWVzc2FnZTpcbiAgICAgICAgICAgIGBkeW5hbWljIGltcG9ydHMgcmVxdWlyZSBhIGxlYWRpbmcgY29tbWVudCBpbiB0aGUgZm9ybSAvKiR7Y2h1bmtTdWJzdHJGb3JtYXR9Ki9gLFxuICAgICAgICB9KTtcbiAgICAgIH1cbiAgICB9XG5cbiAgICByZXR1cm4ge1xuICAgICAgSW1wb3J0RXhwcmVzc2lvbihub2RlKSB7XG4gICAgICAgIHJ1bihub2RlLCBub2RlLnNvdXJjZSk7XG4gICAgICB9LFxuXG4gICAgICBDYWxsRXhwcmVzc2lvbihub2RlKSB7XG4gICAgICAgIGlmIChub2RlLmNhbGxlZS50eXBlICE9PSAnSW1wb3J0JyAmJiBpbXBvcnRGdW5jdGlvbnMuaW5kZXhPZihub2RlLmNhbGxlZS5uYW1lKSA8IDApIHtcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cblxuICAgICAgICBydW4obm9kZSwgbm9kZS5hcmd1bWVudHNbMF0pO1xuICAgICAgfSxcbiAgICB9O1xuICB9LFxufTtcbiJdfQ==
|