Skip to content

Commit

Permalink
feature: @putout/minify: quotes: add ability to override (coderaiser/…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Sep 16, 2024
1 parent ea80f1d commit e9fcd9a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ You can also pass options to `minify`. Here is list of default options:

```js
({
quotes: `'`,
fixCount: 1, // the more fixCount - less output size
conditions: false,
mangleClassNames: true,
Expand Down
5 changes: 5 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const match = {
'@stylistic/js/no-extra-parens': 'off',
'prefer-arrow-callback': 'off',
},
'**/*-fix.*': {
'@stylistic/js/quotes': 'off',
'@stylistic/js/eol-last': 'off',
'@stylistic/js/space-infix-ops': 'off',
},
};

export default [
Expand Down
4 changes: 4 additions & 0 deletions lib/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {getFirstPassOptions} from './plugins.js';

export const minify = (source, options = {}) => {
const ast = parse(source);
const {quote = `'`} = options;

transform(ast, source, getFirstPassOptions(options));

Expand All @@ -14,10 +15,13 @@ export const minify = (source, options = {}) => {
indent: '',
splitter: ' ',
endOfFile: '',
quote,
},
semantics: {
comments: false,
roundBraces: false,
encodeDoubleQuotes: true,
encodeSingleQuotes: true,
},
});

Expand Down
2 changes: 1 addition & 1 deletion test/fixture/quotes-fix.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
var a='hello\'x';(()=>a)(a);
console.log("hello\'x");console.log("Can't start parsing from rule \""+"hello"+"\".");
8 changes: 5 additions & 3 deletions test/fixture/quotes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const a = "hello'x";
const fn = () => a;
fn(a);
const a = 'hello\'x';
console.log(a);
// eslint-disable-next-line @stylistic/js/quotes
console.log("Can't start parsing from rule \"" + "hello" + "\".");

8 changes: 7 additions & 1 deletion test/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,13 @@ test('@putout/minify: increment', (t) => {
});

test('@putout/minify: quotes', (t) => {
t.minify('quotes');
t.minify('quotes', {
quote: '"',
expected: [
`hello'x`,
`Can't start parsing from rule "hello".`,
],
});
t.end();
});

Expand Down

0 comments on commit e9fcd9a

Please sign in to comment.