vendor/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js in jass-0.9.1 vs vendor/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js in jass-0.9.3

- old
+ new

@@ -19,17 +19,25 @@ 'const': true, 'let': true }; var extractors = { + Literal: function Literal ( names, param ) { + names.push( param.value ); + }, + Identifier: function Identifier ( names, param ) { names.push( param.name ); }, ObjectPattern: function ObjectPattern ( names, param ) { param.properties.forEach( function (prop) { - extractors[ prop.key.type ]( names, prop.key ); + if ( prop.type === 'RestElement' ) { + extractors.RestElement( names, prop ); + } else { + extractors[ (prop.value || prop.key).type ]( names, prop.value || prop.key ); + } }); }, ArrayPattern: function ArrayPattern ( names, param ) { param.elements.forEach( function (element) { @@ -77,11 +85,11 @@ if ( !isBlockDeclaration && this.isBlockScope ) { // it's a `var` or function node, and this // is a block scope, so we need to go up this.parent.addDeclaration( node, isBlockDeclaration, isVar ); - } else { + } else if ( node.id ) { extractNames( node.id ).forEach( function (name) { this$1.declarations[ name ] = true; }); } }; @@ -215,9 +223,80 @@ if ( /\d/.test( str[0] ) || blacklisted[ str ] ) { str = "_" + str; } return str; } +function serializeArray (arr, indent, baseIndent) { + var output = '['; + var separator = indent ? '\n' + baseIndent + indent : ''; + for (var i = 0; i < arr.length; i++) { + var key = arr[i]; + output += "" + (i > 0 ? ',' : '') + separator + (serialize(key, indent, baseIndent + indent)); + } + return output + (indent ? '\n' + baseIndent : '') + "]"; +} + +function serializeObject (obj, indent, baseIndent) { + var output = '{'; + var separator = indent ? '\n' + baseIndent + indent : ''; + var keys = Object.keys(obj); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + var stringKey = makeLegalIdentifier(key) === key ? key : JSON.stringify(key); + output += "" + (i > 0 ? ',' : '') + separator + stringKey + ":" + (indent ? ' ' : '') + (serialize(obj[key], indent, baseIndent + indent)); + } + return output + (indent ? '\n' + baseIndent : '') + "}"; +} + +function serialize (obj, indent, baseIndent) { + if (obj === Infinity) + { return 'Infinity'; } + if (obj instanceof Date) + { return 'new Date(' + obj.getTime() + ')'; } + if (obj instanceof RegExp) + { return obj.toString(); } + if (typeof obj === 'number' && isNaN(obj)) + { return 'NaN'; } + if (Array.isArray(obj)) + { return serializeArray(obj, indent, baseIndent); } + if (obj === null) + { return 'null'; } + if (typeof obj === 'object') + { return serializeObject(obj, indent, baseIndent); } + return JSON.stringify(obj); +} + +// convert data object into separate named exports (and default) +function dataToNamedExports (data, options) { + if ( options === void 0 ) options = {}; + + var t = options.compact ? '' : 'indent' in options ? options.indent : '\t'; + var _ = options.compact ? '' : ' '; + var n = options.compact ? '' : '\n'; + var declarationType = options.preferConst ? 'const' : 'var'; + + if (options.namedExports === false || typeof data !== 'object' || Array.isArray(data) || data === null) + { return ("export default" + _ + (serialize( data, options.compact ? null : t, '' )) + ";"); } + + var namedExportCode = ''; + var defaultExportRows = []; + var dataKeys = Object.keys(data); + for (var i = 0; i < dataKeys.length; i++) { + var key = dataKeys[i]; + if (key === makeLegalIdentifier(key)) { + if (options.objectShorthand) + { defaultExportRows.push(key); } + else + { defaultExportRows.push((key + ":" + _ + key)); } + namedExportCode += "export " + declarationType + " " + key + _ + "=" + _ + (serialize(data[key], options.compact ? null : t, '')) + ";" + n; + } else { + defaultExportRows.push(((JSON.stringify(key)) + ": " + (serialize(data[key], options.compact ? null : t, '')))); + } + } + return namedExportCode + "export default" + _ + "{" + n + t + (defaultExportRows.join(("," + n + t))) + n + "};" + n; +} + exports.addExtension = addExtension; exports.attachScopes = attachScopes; exports.createFilter = createFilter; exports.makeLegalIdentifier = makeLegalIdentifier; +exports.dataToEsm = dataToNamedExports;