Browse Source

only exclude strings with newlines, and crop out enclosing quotes - fixes #166

better-aggressive
Rich Harris 9 years ago
parent
commit
f925103863
  1. 6
      src/Statement.js
  2. 6
      test/form/string-indentation-b/_config.js
  3. 8
      test/form/string-indentation-b/_expected/amd.js
  4. 6
      test/form/string-indentation-b/_expected/cjs.js
  5. 4
      test/form/string-indentation-b/_expected/es6.js
  6. 8
      test/form/string-indentation-b/_expected/iife.js
  7. 12
      test/form/string-indentation-b/_expected/umd.js
  8. 5
      test/form/string-indentation-b/main.js

6
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;

6
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'
}
};

8
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' );
});

6
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' );

4
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' );

8
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' );
})();

12
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' );
}));

5
test/form/string-indentation-b/main.js

@ -0,0 +1,5 @@
var a = 'a',
b = 'b';
assert.equal( a, 'a' );
assert.equal( b, 'b' );
Loading…
Cancel
Save