Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
#__NO_SIDE_EFFECTS__
annotation for function declarat…
…ion (#5024) * feat: init * chore: update * chore: updates * chore: update * test: add test for jsdoc * chore: coverage * feat: change the anntation to `__NO_SIDE_EFFECTS__` * chore: coverage * chore: update suggestions * docs: add docs * Slightly clarify wording --------- Co-authored-by: Lukas Taegert-Atkinson <[email protected]>
- Loading branch information
1 parent
7bbbcb5
commit bcd6496
Showing
18 changed files
with
370 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/form/samples/no-side-effects-function-declaration-preserve/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// tests compiled from https://github.com/mishoo/UglifyJS2/blob/88c8f4e363e0d585b33ea29df560243d3dc74ce1/test/compress/pure_funcs.js | ||
|
||
module.exports = defineTest({ | ||
description: 'preserve __NO_SIDE_EFFECTS__ annotations for function declarations' | ||
}); |
77 changes: 77 additions & 0 deletions
77
test/form/samples/no-side-effects-function-declaration-preserve/_expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*#__NO_SIDE_EFFECTS__*/ | ||
function fnFromSub (args) { | ||
console.log(args); | ||
return args | ||
} | ||
|
||
function fnPure(args) { | ||
return args | ||
} | ||
|
||
function fnEffects(args) { | ||
console.log(args); | ||
return args | ||
} | ||
|
||
/*#__NO_SIDE_EFFECTS__*/ | ||
function fnA (args) { | ||
console.log(args); | ||
return args | ||
} | ||
|
||
/*#__NO_SIDE_EFFECTS__*/ | ||
function fnB (args) { | ||
console.log(args); | ||
return args | ||
} | ||
|
||
const fnC = /*#__NO_SIDE_EFFECTS__*/ (args) => { | ||
console.log(args); | ||
return args | ||
}; | ||
|
||
|
||
/*#__NO_SIDE_EFFECTS__*/ | ||
const fnD = (args) => { | ||
console.log(args); | ||
return args | ||
}; | ||
|
||
/*#__NO_SIDE_EFFECTS__*/ | ||
const fnE = (args) => { | ||
console.log(args); | ||
return args | ||
}; | ||
|
||
/** | ||
* This is a jsdoc comment, with no side effects annotation | ||
* | ||
* @param {any} args | ||
* @__NO_SIDE_EFFECTS__ | ||
*/ | ||
const fnF = (args) => { | ||
console.log(args); | ||
return args | ||
}; | ||
|
||
const fnAlias = fnA; | ||
|
||
/** | ||
* Have both annotations | ||
* | ||
* @__PURE__ | ||
* @__NO_SIDE_EFFECTS__ | ||
*/ | ||
const fnBothAnnotations = (args) => { | ||
console.log(args); | ||
return args | ||
}; | ||
|
||
// This annonation get ignored | ||
|
||
let fnLet = (args) => { | ||
console.log(args); | ||
return args | ||
}; | ||
|
||
export { fnA, fnAlias, fnB, fnBothAnnotations, fnC, fnD, fnE, fnEffects, fnF, fnFromSub, fnLet, fnPure }; |
Oops, something went wrong.