diff --git a/src/Statement.js b/src/Statement.js index 5c6ddd08b57..8a5ff4e66e4 100644 --- a/src/Statement.js +++ b/src/Statement.js @@ -95,8 +95,10 @@ export default class Statement { walk( this.node, { enter ( node, parent ) { - const isStringLiteral = node.type === 'TemplateElement' || ( node.type === 'Literal' && typeof node.value === 'string' ); - if ( isStringLiteral ) stringLiteralRanges.push([ node.start, node.end ]); + if ( node.type === 'TemplateElement' ) stringLiteralRanges.push([ node.start, node.end ]); + if ( node.type === 'Literal' && typeof node.value === 'string' && /\n/.test( node.raw ) ) { + stringLiteralRanges.push([ node.start + 1, node.end - 1 ]); + } if ( node._scope ) scope = node._scope; if ( /Function/.test( node.type ) && !isIife( node, parent ) ) readDepth += 1; diff --git a/test/form/string-indentation-b/_config.js b/test/form/string-indentation-b/_config.js new file mode 100644 index 00000000000..99f2d9cacb7 --- /dev/null +++ b/test/form/string-indentation-b/_config.js @@ -0,0 +1,6 @@ +module.exports = { + description: 'handles multiple var declarations inited to strings (#166)', + options: { + moduleName: 'myBundle' + } +}; diff --git a/test/form/string-indentation-b/_expected/amd.js b/test/form/string-indentation-b/_expected/amd.js new file mode 100644 index 00000000000..f646cb2e377 --- /dev/null +++ b/test/form/string-indentation-b/_expected/amd.js @@ -0,0 +1,8 @@ +define(function () { 'use strict'; + + var a = 'a'; + var b = 'b'; + assert.equal( a, 'a' ); + assert.equal( b, 'b' ); + +}); \ No newline at end of file diff --git a/test/form/string-indentation-b/_expected/cjs.js b/test/form/string-indentation-b/_expected/cjs.js new file mode 100644 index 00000000000..7c799d31f16 --- /dev/null +++ b/test/form/string-indentation-b/_expected/cjs.js @@ -0,0 +1,6 @@ +'use strict'; + +var a = 'a'; +var b = 'b'; +assert.equal( a, 'a' ); +assert.equal( b, 'b' ); \ No newline at end of file diff --git a/test/form/string-indentation-b/_expected/es6.js b/test/form/string-indentation-b/_expected/es6.js new file mode 100644 index 00000000000..7ab432c7e04 --- /dev/null +++ b/test/form/string-indentation-b/_expected/es6.js @@ -0,0 +1,4 @@ +var a = 'a'; +var b = 'b'; +assert.equal( a, 'a' ); +assert.equal( b, 'b' ); \ No newline at end of file diff --git a/test/form/string-indentation-b/_expected/iife.js b/test/form/string-indentation-b/_expected/iife.js new file mode 100644 index 00000000000..0ffdcbe3d2b --- /dev/null +++ b/test/form/string-indentation-b/_expected/iife.js @@ -0,0 +1,8 @@ +(function () { 'use strict'; + + var a = 'a'; + var b = 'b'; + assert.equal( a, 'a' ); + assert.equal( b, 'b' ); + +})(); \ No newline at end of file diff --git a/test/form/string-indentation-b/_expected/umd.js b/test/form/string-indentation-b/_expected/umd.js new file mode 100644 index 00000000000..c137f1bc2be --- /dev/null +++ b/test/form/string-indentation-b/_expected/umd.js @@ -0,0 +1,12 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + factory(); +}(this, function () { 'use strict'; + + var a = 'a'; + var b = 'b'; + assert.equal( a, 'a' ); + assert.equal( b, 'b' ); + +})); \ No newline at end of file diff --git a/test/form/string-indentation-b/main.js b/test/form/string-indentation-b/main.js new file mode 100644 index 00000000000..e0a7210c91a --- /dev/null +++ b/test/form/string-indentation-b/main.js @@ -0,0 +1,5 @@ +var a = 'a', + b = 'b'; + +assert.equal( a, 'a' ); +assert.equal( b, 'b' );