Skip to content

Commit

Permalink
only exclude strings with newlines, and crop out enclosing quotes - f…
Browse files Browse the repository at this point in the history
…ixes #166
  • Loading branch information
Rich-Harris committed Oct 5, 2015
1 parent 65e7cb9 commit f925103
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions test/form/string-indentation-b/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
description: 'handles multiple var declarations inited to strings (#166)',
options: {
moduleName: 'myBundle'
}
};
8 changes: 8 additions & 0 deletions test/form/string-indentation-b/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
define(function () { 'use strict';

var a = 'a';
var b = 'b';
assert.equal( a, 'a' );
assert.equal( b, 'b' );

});
6 changes: 6 additions & 0 deletions test/form/string-indentation-b/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

var a = 'a';
var b = 'b';
assert.equal( a, 'a' );
assert.equal( b, 'b' );
4 changes: 4 additions & 0 deletions test/form/string-indentation-b/_expected/es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var a = 'a';
var b = 'b';
assert.equal( a, 'a' );
assert.equal( b, 'b' );
8 changes: 8 additions & 0 deletions test/form/string-indentation-b/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(function () { 'use strict';

var a = 'a';
var b = 'b';
assert.equal( a, 'a' );
assert.equal( b, 'b' );

})();
12 changes: 12 additions & 0 deletions test/form/string-indentation-b/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -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' );

}));
5 changes: 5 additions & 0 deletions test/form/string-indentation-b/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var a = 'a',
b = 'b';

assert.equal( a, 'a' );
assert.equal( b, 'b' );

0 comments on commit f925103

Please sign in to comment.