From 101ad286b5690a6080b2f9903f832e4c75f5f7c6 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 7 Jan 2017 12:52:50 -0500 Subject: [PATCH] use options.indent for UMD block - fixes #797 --- src/finalisers/umd.js | 2 +- test/form/indent-false/_expected/amd.js | 2 +- test/form/indent-false/_expected/cjs.js | 2 +- test/form/indent-false/_expected/es.js | 2 +- test/form/indent-false/_expected/iife.js | 2 +- test/form/indent-false/_expected/umd.js | 4 ++-- test/form/indent-false/main.js | 2 +- test/form/indent-spaces/_config.js | 7 +++++++ test/form/indent-spaces/_expected/amd.js | 9 +++++++++ test/form/indent-spaces/_expected/cjs.js | 7 +++++++ test/form/indent-spaces/_expected/es.js | 5 +++++ test/form/indent-spaces/_expected/iife.js | 10 ++++++++++ test/form/indent-spaces/_expected/umd.js | 13 +++++++++++++ test/form/indent-spaces/main.js | 3 +++ 14 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 test/form/indent-spaces/_config.js create mode 100644 test/form/indent-spaces/_expected/amd.js create mode 100644 test/form/indent-spaces/_expected/cjs.js create mode 100644 test/form/indent-spaces/_expected/es.js create mode 100644 test/form/indent-spaces/_expected/iife.js create mode 100644 test/form/indent-spaces/_expected/umd.js create mode 100644 test/form/indent-spaces/main.js diff --git a/src/finalisers/umd.js b/src/finalisers/umd.js index 0a93e03..5144a8e 100644 --- a/src/finalisers/umd.js +++ b/src/finalisers/umd.js @@ -78,7 +78,7 @@ export default function umd ( bundle, magicString, { exportMode, indentString, i ${globalExport}; }(this, (function (${args}) {${useStrict} - `.replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() ); + `.replace( /^\t\t/gm, '' ).replace( /^\t/gm, indentString || '\t' ); // var foo__default = 'default' in foo ? foo['default'] : foo; const interopBlock = getInteropBlock( bundle, options ); diff --git a/test/form/indent-false/_expected/amd.js b/test/form/indent-false/_expected/amd.js index 07c823c..2ef21fb 100644 --- a/test/form/indent-false/_expected/amd.js +++ b/test/form/indent-false/_expected/amd.js @@ -1,7 +1,7 @@ define(function () { 'use strict'; function foo () { - console.log( 'indented with tabs' ); + console.log( 'not indented' ); } return foo; diff --git a/test/form/indent-false/_expected/cjs.js b/test/form/indent-false/_expected/cjs.js index 7f6e0b9..04d1ea3 100644 --- a/test/form/indent-false/_expected/cjs.js +++ b/test/form/indent-false/_expected/cjs.js @@ -1,7 +1,7 @@ 'use strict'; function foo () { - console.log( 'indented with tabs' ); + console.log( 'not indented' ); } module.exports = foo; diff --git a/test/form/indent-false/_expected/es.js b/test/form/indent-false/_expected/es.js index d4b23ef..2710c80 100644 --- a/test/form/indent-false/_expected/es.js +++ b/test/form/indent-false/_expected/es.js @@ -1,5 +1,5 @@ function foo () { - console.log( 'indented with tabs' ); + console.log( 'not indented' ); } export default foo; diff --git a/test/form/indent-false/_expected/iife.js b/test/form/indent-false/_expected/iife.js index 54ba717..0b46c84 100644 --- a/test/form/indent-false/_expected/iife.js +++ b/test/form/indent-false/_expected/iife.js @@ -2,7 +2,7 @@ var foo = (function () { 'use strict'; function foo () { - console.log( 'indented with tabs' ); + console.log( 'not indented' ); } return foo; diff --git a/test/form/indent-false/_expected/umd.js b/test/form/indent-false/_expected/umd.js index c0289b0..22e4c7d 100644 --- a/test/form/indent-false/_expected/umd.js +++ b/test/form/indent-false/_expected/umd.js @@ -5,9 +5,9 @@ }(this, (function () { 'use strict'; function foo () { - console.log( 'indented with tabs' ); + console.log( 'not indented' ); } return foo; -}))); \ No newline at end of file +}))); diff --git a/test/form/indent-false/main.js b/test/form/indent-false/main.js index 10005f9..e68e7b3 100644 --- a/test/form/indent-false/main.js +++ b/test/form/indent-false/main.js @@ -1,3 +1,3 @@ export default function foo () { - console.log( 'indented with tabs' ); + console.log( 'not indented' ); } diff --git a/test/form/indent-spaces/_config.js b/test/form/indent-spaces/_config.js new file mode 100644 index 0000000..d684967 --- /dev/null +++ b/test/form/indent-spaces/_config.js @@ -0,0 +1,7 @@ +module.exports = { + description: 'auto-indents with indent: true', + options: { + moduleName: 'foo', + indent: ' ' + } +}; diff --git a/test/form/indent-spaces/_expected/amd.js b/test/form/indent-spaces/_expected/amd.js new file mode 100644 index 0000000..445c02f --- /dev/null +++ b/test/form/indent-spaces/_expected/amd.js @@ -0,0 +1,9 @@ +define(function () { 'use strict'; + + function foo () { + console.log( 'indented with tabs' ); + } + + return foo; + +}); diff --git a/test/form/indent-spaces/_expected/cjs.js b/test/form/indent-spaces/_expected/cjs.js new file mode 100644 index 0000000..7f6e0b9 --- /dev/null +++ b/test/form/indent-spaces/_expected/cjs.js @@ -0,0 +1,7 @@ +'use strict'; + +function foo () { + console.log( 'indented with tabs' ); +} + +module.exports = foo; diff --git a/test/form/indent-spaces/_expected/es.js b/test/form/indent-spaces/_expected/es.js new file mode 100644 index 0000000..d4b23ef --- /dev/null +++ b/test/form/indent-spaces/_expected/es.js @@ -0,0 +1,5 @@ +function foo () { + console.log( 'indented with tabs' ); +} + +export default foo; diff --git a/test/form/indent-spaces/_expected/iife.js b/test/form/indent-spaces/_expected/iife.js new file mode 100644 index 0000000..f83141c --- /dev/null +++ b/test/form/indent-spaces/_expected/iife.js @@ -0,0 +1,10 @@ +var foo = (function () { + 'use strict'; + + function foo () { + console.log( 'indented with tabs' ); + } + + return foo; + +}()); diff --git a/test/form/indent-spaces/_expected/umd.js b/test/form/indent-spaces/_expected/umd.js new file mode 100644 index 0000000..86fd887 --- /dev/null +++ b/test/form/indent-spaces/_expected/umd.js @@ -0,0 +1,13 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.foo = factory()); +}(this, (function () { 'use strict'; + + function foo () { + console.log( 'indented with tabs' ); + } + + return foo; + +}))); diff --git a/test/form/indent-spaces/main.js b/test/form/indent-spaces/main.js new file mode 100644 index 0000000..10005f9 --- /dev/null +++ b/test/form/indent-spaces/main.js @@ -0,0 +1,3 @@ +export default function foo () { + console.log( 'indented with tabs' ); +}