Skip to content

Commit

Permalink
Remove inline option [major]
Browse files Browse the repository at this point in the history
Closes #501.
  • Loading branch information
overlookmotel committed Dec 6, 2023
1 parent e1f9e27 commit 21ec33b
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 191 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ module.exports = (async () => {
| `--entry-chunk-name` | Template for entry point chunk names ([more info](#customizing-chunk-names)) | `[name]` |
| `--split-chunk-name` | Template for split chunk names ([more info](#customizing-chunk-names)) | `[name].[hash]` |
| `--common-chunk-name` | Template for common chunk names ([more info](#customizing-chunk-names)) | `common.[hash]` |
| `--no-inline` | More verbose output. Only useful for debugging. | Inlining enabled |
| `--source-maps` / `-s` | Output source maps. `--source-maps inline` for inline source maps. | Disabled |
| `--no-exec` | Output a file which exports the input rather than executes it. | Exec enabled |
| `--stats` | Output stats file.<br />Provide filename or `true` for `livepack-stats.json`. | Disabled |
Expand All @@ -182,7 +181,6 @@ You can set options in a `livepack.config.json` file rather than on command line
"minify": true,
"mangle": true,
"comments": false,
"inline": true,
"entryChunkName": "[name]",
"splitChunkName": "[name].[hash]",
"commonChunkName": "common.[hash]",
Expand Down Expand Up @@ -310,7 +308,6 @@ serialize( {x: 1}, {
| `minify` | `boolean` | Minify output | `true` |
| `mangle` | `boolean` | Mangle (shorten) variable names | `options.minify` |
| `comments` | `boolean` | Include comments in output | `!options.minify` |
| `inline` | `boolean` | Less verbose output | `true` |
| `files` | `boolean` | `true` to output array of files (see [below](#files)) | `false` for `serialize()`,<br />`true` for `serializeEntries()` |
| `strictEnv` | `boolean` | `true` if environment code will execute in is strict mode (only relevant for `js` format) | `false` for `js` or `cjs` format, `true` for `esm` |
| `entryChunkName` | `string` | Template for entry point chunk names ([more info](#customizing-chunk-names)) | `'[name]'` |
Expand Down
6 changes: 0 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ const {argv} = yargs
type: 'boolean',
default: false
})
.option('inline', {
type: 'boolean',
description: 'Inline code where possible',
default: true
})
.option('mangle', {
type: 'boolean',
description: 'Mangle var names'
Expand Down Expand Up @@ -251,7 +246,6 @@ register({
mapExt: argv.mapExt,
exec: argv.exec,
minify: argv.minify,
inline: argv.inline,
mangle: argv.mangle,
comments: argv.comments,
entryChunkName: argv.entryChunkName,
Expand Down
5 changes: 1 addition & 4 deletions lib/serialize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ function serializeImpl(entries, options) {
* @param {string} [options.mapExt='map'] - Source map file extension
* @param {boolean} [options.exec=false] - If true, export will be called
* @param {boolean} [options.minify=true] - If false, JS is not minified (defaults to true)
* @param {boolean} [options.inline] - If false, every object is a separate var
* (default inherits `options.minify`)
* @param {boolean} [options.mangle] - If false, vars left with original names, rather than shortening
* (default inherits `options.minify`)
* @param {boolean} [options.comments] - If true, comments are left in JS
Expand Down Expand Up @@ -143,9 +141,8 @@ function conformOptions(options, filesDefault) {
assert(!/[/\\]/.test(mapExt), 'options.mapExt must not contain slashes');
}

// Conform `minify`, `inline`, `mangle`, `comments`, `files`, `debug` options
// Conform `minify`, `mangle`, `comments`, `files`, `debug` options
conformBool('minify', true);
conformBool('inline', true);
conformBool('mangle', options.minify); // Mangling defaults to enabled if minifying enabled
conformBool('comments', !options.minify); // Comments defaults to disabled if minifying enabled
conformBool('files', filesDefault);
Expand Down
4 changes: 2 additions & 2 deletions lib/serialize/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ module.exports = {
const varNodes = [],
statementNodes = [],
importNodes = [],
{mangle, inline} = this.options;
{mangle} = this.options;

const queue = [record],
processing = new Map(); // Keyed by record, values = `true` for processed, `false` for processing
Expand Down Expand Up @@ -527,7 +527,7 @@ module.exports = {
// Add var definition to output
const {dependents, assignments} = valRecord;
const nodeIsImport = t.isImportDeclaration(node);
if (inline && dependents.length === 1 && !nodeIsImport) {
if (dependents.length === 1 && !nodeIsImport) {
// Only used once - substitute content in place of var
const {node: parentNode, key} = dependents[0];

Expand Down
30 changes: 9 additions & 21 deletions test/builtInModules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,11 @@ describe('Built-in modules', () => {
in: () => ({path: pathModule, path2: pathModule, path3: pathModule}),
format: 'esm',
minify: true,
validateOutput(obj, {outputJs, mangle, inline}) {
validateOutput(obj, {outputJs, mangle}) {
expect(stripSourceMapComment(outputJs)).toBe(
mangle
? inline
? 'import a from"path";export default{path:a,path2:a,path3:a}'
: 'import a from"path";const b={path:a,path2:a,path3:a};export default b'
: inline
? 'import path from"path";export default{path,path2:path,path3:path}'
: 'import path from"path";const index={path,path2:path,path3:path};export default index'
? 'import a from"path";export default{path:a,path2:a,path3:a}'
: 'import path from"path";export default{path,path2:path,path3:path}'
);
}
});
Expand Down Expand Up @@ -130,15 +126,11 @@ describe('Built-in modules', () => {
in: () => pathJoin,
format: 'esm',
minify: true,
validateOutput(res, {outputJs, mangle, inline}) {
validateOutput(res, {outputJs, mangle}) {
expect(stripSourceMapComment(outputJs)).toBe(
mangle
? inline
? 'import a from"path";export default a.join'
: 'import a from"path";const b=a.join;export default b'
: inline
? 'import path from"path";export default path.join'
: 'import path from"path";const pathJoin=path.join;export default pathJoin'
? 'import a from"path";export default a.join'
: 'import path from"path";export default path.join'
);
}
});
Expand Down Expand Up @@ -174,15 +166,11 @@ describe('Built-in modules', () => {
in: () => ({pathJoin, pathJoin2: pathJoin, pathJoin3: pathJoin}),
format: 'esm',
minify: true,
validateOutput(obj, {outputJs, mangle, inline}) {
validateOutput(obj, {outputJs, mangle}) {
expect(stripSourceMapComment(outputJs)).toBe(
mangle
? inline
? 'import a from"path";const b=a.join;export default{pathJoin:b,pathJoin2:b,pathJoin3:b}'
: 'import a from"path";const b=a.join,c={pathJoin:b,pathJoin2:b,pathJoin3:b};export default c'
: inline
? 'import path from"path";const pathJoin=path.join;export default{pathJoin,pathJoin2:pathJoin,pathJoin3:pathJoin}'
: 'import path from"path";const pathJoin=path.join,index={pathJoin,pathJoin2:pathJoin,pathJoin3:pathJoin};export default index'
? 'import a from"path";const b=a.join;export default{pathJoin:b,pathJoin2:b,pathJoin3:b}'
: 'import path from"path";const pathJoin=path.join;export default{pathJoin,pathJoin2:pathJoin,pathJoin3:pathJoin}'
);
}
});
Expand Down
68 changes: 42 additions & 26 deletions test/cjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,77 @@ const {itSerializesEqual, stripSourceMapComment} = require('./support/index.js')

describe('CJS output format', () => {
itSerializesEqual('protects `module` var', {
in: () => ({module: {a: 1}}),
in() {
const module = {a: 1};
return {module, module2: module};
},
format: 'cjs',
out: 'module.exports={module:{a:1}}',
validateOutput(obj, {outputJs, minify, inline, mangle}) {
if (minify && !inline && !mangle) {
out: 'const a={a:1};module.exports={module:a,module2:a}',
validateOutput(obj, {outputJs, minify, mangle}) {
if (minify && !mangle) {
expect(stripSourceMapComment(outputJs))
.toBe('const module$0={a:1},index={module:module$0};module.exports=index');
.toBe('const module$0={a:1};module.exports={module:module$0,module2:module$0}');
}
}
});

itSerializesEqual('protects `exports` var', {
in: () => ({exports: {a: 1}}),
in() {
const exports = {a: 1};
return {exports, exports2: exports};
},
format: 'cjs',
out: 'module.exports={exports:{a:1}}',
validateOutput(obj, {outputJs, minify, inline, mangle}) {
if (minify && !inline && !mangle) {
out: 'const a={a:1};module.exports={exports:a,exports2:a}',
validateOutput(obj, {outputJs, minify, mangle}) {
if (minify && !mangle) {
expect(stripSourceMapComment(outputJs))
.toBe('const exports$0={a:1},index={exports:exports$0};module.exports=index');
.toBe('const exports$0={a:1};module.exports={exports:exports$0,exports2:exports$0}');
}
}
});

itSerializesEqual('protects `require` var', {
in: () => ({require: {a: 1}}),
in() {
const require = {a: 1};
return {require, require2: require};
},
format: 'cjs',
out: 'module.exports={require:{a:1}}',
validateOutput(obj, {outputJs, minify, inline, mangle}) {
if (minify && !inline && !mangle) {
out: 'const a={a:1};module.exports={require:a,require2:a}',
validateOutput(obj, {outputJs, minify, mangle}) {
if (minify && !mangle) {
expect(stripSourceMapComment(outputJs))
.toBe('const require$0={a:1},index={require:require$0};module.exports=index');
.toBe('const require$0={a:1};module.exports={require:require$0,require2:require$0}');
}
}
});

itSerializesEqual('protects `__dirname` var', {
in: () => ({__dirname: {a: 1}}),
in() {
const __dirname = {a: 1};
return {__dirname, __dirname2: __dirname};
},
format: 'cjs',
out: 'module.exports={__dirname:{a:1}}',
validateOutput(obj, {outputJs, minify, inline, mangle}) {
if (minify && !inline && !mangle) {
out: 'const a={a:1};module.exports={__dirname:a,__dirname2:a}',
validateOutput(obj, {outputJs, minify, mangle}) {
if (minify && !mangle) {
expect(stripSourceMapComment(outputJs))
.toBe('const __dirname$0={a:1},index={__dirname:__dirname$0};module.exports=index');
.toBe('const __dirname$0={a:1};module.exports={__dirname:__dirname$0,__dirname2:__dirname$0}');
}
}
});

itSerializesEqual('protects `__filename` var', {
in: () => ({__filename: {a: 1}}),
in() {
const __filename = {a: 1};
return {__filename, __filename2: __filename};
},
format: 'cjs',
out: 'module.exports={__filename:{a:1}}',
validateOutput(obj, {outputJs, minify, inline, mangle}) {
if (minify && !inline && !mangle) {
expect(stripSourceMapComment(outputJs))
.toBe('const __filename$0={a:1},index={__filename:__filename$0};module.exports=index');
out: 'const a={a:1};module.exports={__filename:a,__filename2:a}',
validateOutput(obj, {outputJs, minify, mangle}) {
if (minify && !mangle) {
expect(stripSourceMapComment(outputJs)).toBe(
'const __filename$0={a:1};module.exports={__filename:__filename$0,__filename2:__filename$0}'
);
}
}
});
Expand Down
32 changes: 4 additions & 28 deletions test/commonjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,8 @@ describe('`__dirname`', () => {
return () => __dirname;
},
out: '()=>__dirname',
validateOutput(fn, {outputJs, minify, inline, mangle}) {
expect(stripLineBreaks(outputJs)).toBe(
minify
? inline
? '()=>__dirname'
: mangle
? '(()=>{const a=(0,()=>__dirname);return a})()'
: '(()=>{const index=(0,()=>__dirname);return index})()'
: inline
? '() => __dirname'
: mangle
? '(() => {const a = (0, () => __dirname);return a;})()'
: '(() => {const index = (0, () => __dirname);return index;})()'
);
validateOutput(fn, {outputJs, minify}) {
expect(stripLineBreaks(outputJs)).toBe(minify ? '()=>__dirname' : '() => __dirname');
}
});
});
Expand All @@ -133,20 +121,8 @@ describe('`__filename`', () => {
return () => __filename;
},
out: '()=>__filename',
validateOutput(fn, {outputJs, minify, inline, mangle}) {
expect(stripLineBreaks(outputJs)).toBe(
minify
? inline
? '()=>__filename'
: mangle
? '(()=>{const a=(0,()=>__filename);return a})()'
: '(()=>{const index=(0,()=>__filename);return index})()'
: inline
? '() => __filename'
: mangle
? '(() => {const a = (0, () => __filename);return a;})()'
: '(() => {const index = (0, () => __filename);return index;})()'
);
validateOutput(fn, {outputJs, minify}) {
expect(stripLineBreaks(outputJs)).toBe(minify ? '()=>__filename' : '() => __filename');
}
});
});
8 changes: 4 additions & 4 deletions test/eval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2196,7 +2196,7 @@ describe('eval', () => {
")(a)
}
})()`,
validate({evalFn, ext, console: ext2}, {isOutput, minify, mangle, inline, outputJs}) {
validate({evalFn, ext, console: ext2}, {isOutput, minify, mangle, outputJs}) {
expect(evalFn).toBeFunction();
const res = evalFn();
expect(res).toBeObject();
Expand All @@ -2206,7 +2206,7 @@ describe('eval', () => {
expect(ext2).toBe(ext);

// Test top level var naming unaffected by global use inside eval when mangle disabled
if (isOutput && minify && !mangle && inline) {
if (isOutput && minify && !mangle) {
expect(stripSourceMapComment(outputJs)).toBe(stripLineBreaks(`
(()=>{
const console={x:1};
Expand Down Expand Up @@ -2242,7 +2242,7 @@ describe('eval', () => {
evalFn:(0,eval)("()=>eval(\\"({console, typeofA: typeof a})\\")")
}
})()`,
validate({evalFn, ext, console: ext2}, {isOutput, minify, mangle, inline, outputJs}) {
validate({evalFn, ext, console: ext2}, {isOutput, minify, mangle, outputJs}) {
expect(evalFn).toBeFunction();
const res = evalFn();
expect(res).toBeObject();
Expand All @@ -2252,7 +2252,7 @@ describe('eval', () => {
expect(ext2).toBe(ext);

// Test top level var naming unaffected by global use inside eval when mangle disabled
if (isOutput && minify && !mangle && inline) {
if (isOutput && minify && !mangle) {
expect(stripSourceMapComment(outputJs)).toBe(stripLineBreaks(`
(()=>{
const console={x:1};
Expand Down
9 changes: 2 additions & 7 deletions test/functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8429,7 +8429,6 @@ describe('Functions', () => {
return (x, y) => [a, x, y]; // eslint-disable-line no-undef
},
minify: true,
inline: true,
mangle: true,
validateOutput(fn, {outputJs}) {
expect(stripSourceMapComment(outputJs)).toBe('(b,c)=>[a,b,c]');
Expand All @@ -8442,7 +8441,6 @@ describe('Functions', () => {
return {a: fn, b: fn};
},
minify: true,
inline: true,
mangle: false,
validateOutput(fn, {outputJs}) {
expect(stripSourceMapComment(outputJs)).toBe(
Expand All @@ -8457,7 +8455,6 @@ describe('Functions', () => {
return (x, y) => function a() { return [x, y]; };
},
minify: true,
inline: true,
mangle: true,
validateOutput(fn, {outputJs}) {
expect(stripSourceMapComment(outputJs)).toBe('(b,c)=>function a(){return[b,c]}');
Expand All @@ -8472,7 +8469,6 @@ describe('Functions', () => {
return fn;
},
minify: true,
inline: true,
validateOutput(fn, {outputJs, mangle}) {
expect(stripSourceMapComment(outputJs)).toBe(
mangle
Expand All @@ -8488,7 +8484,6 @@ describe('Functions', () => {
return {console: function() { return console; }}.console;
},
minify: true,
inline: true,
validateOutput(fn, {outputJs}) {
expect(stripSourceMapComment(outputJs)).toBe(
'Object.defineProperties(function(){return console},{name:{value:"console"}})'
Expand Down Expand Up @@ -11170,7 +11165,7 @@ describe('Functions', () => {
return {
in: () => (0, eval)(fnStrWithExtAdded), // eslint-disable-line no-eval
strictEnv: false,
validate(wrapperFn, {isOutput, outputJs, minify, mangle, inline}) {
validate(wrapperFn, {isOutput, outputJs, minify, mangle}) {
const fn = wrapperFn();
expect(fn).toBeFunction();
expect(fn).toHaveLength(len);
Expand All @@ -11181,7 +11176,7 @@ describe('Functions', () => {
expect(fn(...callArgs)).toEqual(expectedRes);
}

if (isOutput && minify && !mangle && inline) {
if (isOutput && minify && !mangle) {
expect(stripLineBreaks(outputJs)).toBe(fnStrWithExtAdded.replace(/ /g, ''));
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/globals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('Globals', () => {

itSerializesEqual('vars named with full path', {
minify: true,
inline: true,
mangle: false,
in: () => ({a: Object.assign, b: Object.assign}),
validateOutput(obj, {outputJs}) {
Expand Down Expand Up @@ -100,7 +99,6 @@ describe('Globals', () => {

itSerializesEqual('vars named with full path', {
minify: true,
inline: true,
mangle: false,
in: () => ({a: Array.prototype.slice, b: Array.prototype.slice}),
validateOutput(obj, {outputJs}) {
Expand Down
Loading

0 comments on commit 21ec33b

Please sign in to comment.