Sitelet https://github.com/rollup/rollup/commit/e6f6f368cff317893d3226f00470685ebe4a51f2
Skip to content

Commit e6f6f36

Browse files
authored
fix: forward __NO_SIDE_EFFECTS__ annotations to function expressions in variable declarations (#6272)
Handle __NO_SIDE_EFFECTS__ for function expressions in declarations.
1 parent 7f00689 commit e6f6f36

3 files changed

Lines changed: 93 additions & 25 deletions

File tree

‎rust/parse_ast/src/ast_nodes/variable_declarator.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl AstConverter<'_> {
1717
);
1818
let forwarded_annotations = match &variable_declarator.init {
1919
Some(expression) => match &**expression {
20-
Expr::Arrow(_) => {
20+
Expr::Arrow(_) | Expr::Fn(_) => {
2121
let annotations = self
2222
.index_converter
2323
.take_collected_annotations(AnnotationKind::NoSideEffects);

‎test/form/samples/no-side-effects-function-declaration/functions.js‎

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,64 @@ export function fnB (args) {
2020
return args
2121
}
2222

23-
export const fnC = /*#__NO_SIDE_EFFECTS__*/ (args) => {
23+
export const fnC1 = /*#__NO_SIDE_EFFECTS__*/ (args) => {
2424
console.log(args)
2525
return args
2626
}
2727

28+
export const fnC2 = /*#__NO_SIDE_EFFECTS__*/ function (args) {
29+
console.log(args);
30+
return args;
31+
}
2832

2933
/*#__NO_SIDE_EFFECTS__*/
30-
const fnD = (args) => {
34+
const fnD1 = (args) => {
3135
console.log(args)
3236
return args
3337
}
3438

35-
export { fnD }
39+
/*#__NO_SIDE_EFFECTS__*/
40+
const fnD2 = function (args) {
41+
console.log(args);
42+
return args;
43+
}
44+
45+
export { fnD1, fnD2 }
3646

3747
/*#__NO_SIDE_EFFECTS__*/
38-
export const fnE = (args) => {
48+
export const fnE1 = (args) => {
3949
console.log(args)
4050
return args
4151
}
4252

53+
/*#__NO_SIDE_EFFECTS__*/
54+
export const fnE2 = function (args) {
55+
console.log(args);
56+
return args;
57+
}
58+
4359
/**
4460
* This is a jsdoc comment, with pure annotation
4561
*
4662
* @param {any} args
4763
* @__NO_SIDE_EFFECTS__
4864
*/
49-
export const fnF = (args) => {
65+
export const fnF1 = (args) => {
5066
console.log(args)
5167
return args
5268
}
5369

70+
/**
71+
* This is a jsdoc comment, with pure annotation
72+
*
73+
* @param {any} args
74+
* @__NO_SIDE_EFFECTS__
75+
*/
76+
export const fnF2 = function (args) {
77+
console.log(args);
78+
return args;
79+
}
80+
5481
// #__NO_SIDE_EFFECTS__
5582
export async function fnG(args) {
5683
console.log(args)
@@ -60,16 +87,28 @@ export async function fnG(args) {
6087
/**
6188
* #__NO_SIDE_EFFECTS__
6289
*/
63-
export const fnH = async (args) => {
90+
export const fnH1 = async (args) => {
6491
console.log(args)
6592
return args
6693
}
6794

68-
export const fnI = /*#__NO_SIDE_EFFECTS__*/ async (args) => {
95+
/**
96+
* #__NO_SIDE_EFFECTS__
97+
*/
98+
export const fnH2 = async function (args) {
99+
console.log(args);
100+
return args;
101+
}
102+
103+
export const fnI1 = /*#__NO_SIDE_EFFECTS__*/ async (args) => {
69104
console.log(args)
70105
return args
71106
}
72107

108+
export const fnI2 = /*#__NO_SIDE_EFFECTS__*/ async function (args) {
109+
console.log(args);
110+
return args;
111+
}
73112

74113
/**
75114
* #__NO_SIDE_EFFECTS__
Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
1-
import fnDefault, { fnPure, fnEffects, fnA, fnB, fnC, fnD, fnE, fnF, fnI, fnG, fnJ, fnK, fnAlias, fnFromSub } from './functions'
1+
import fnDefault, {
2+
fnA,
3+
fnAlias,
4+
fnB,
5+
fnC1,
6+
fnC2,
7+
fnD1,
8+
fnD2,
9+
fnE1,
10+
fnE2,
11+
fnEffects,
12+
fnF1,
13+
fnF2,
14+
fnFromSub,
15+
fnG,
16+
fnH1,
17+
fnH2,
18+
fnI1,
19+
fnI2,
20+
fnJ,
21+
fnK,
22+
fnPure
23+
} from './functions';
224

3-
const pure = fnPure(1)
4-
const effects = fnEffects(2)
25+
const pure = fnPure(1);
26+
const effects = fnEffects(2);
527

6-
const a = fnA(1)
7-
const b = fnB(2)
8-
const c = fnC(3)
9-
const d = fnD(4)
10-
const e = fnE(5)
11-
const f = fnF(6)
12-
const g = fnG(7)
13-
const i = fnI(8)
14-
const j = fnJ(9)
15-
const k = fnK(10)
28+
const a = fnA(1);
29+
const b = fnB(2);
30+
const c = fnC1(3);
31+
const d = fnC2(3);
32+
const e = fnD1(4);
33+
const f = fnD2(4);
34+
const g = fnE1(5);
35+
const h = fnE2(5);
36+
const i = fnF1(6);
37+
const j = fnF2(6);
38+
const k = fnG(7);
39+
const l = fnH1(7);
40+
const m = fnH2(7);
41+
const n = fnI1(8);
42+
const o = fnI2(8);
43+
const p = fnJ(9);
44+
const q = fnK(10);
1645

17-
const defaults = fnDefault(3)
18-
const alias = fnAlias(6)
19-
const fromSub = fnFromSub(7)
46+
const defaults = fnDefault(3);
47+
const alias = fnAlias(6);
48+
const fromSub = fnFromSub(7);
2049

21-
const _ = /*#__PURE__*/ fnEffects(1)
50+
const _ = /*#__PURE__*/ fnEffects(1);

0 commit comments

Comments
 (0)