Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure annotations are removed together with the annotated nodes even
if this is not covered by normal comment removal.
- Loading branch information
1 parent
df1fef2
commit 1ff583c
Showing
15 changed files
with
161 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
import MagicString from 'magic-string'; | ||
import { RenderOptions } from '../../utils/renderHelpers'; | ||
import * as NodeType from './NodeType'; | ||
import { StatementBase } from './shared/Node'; | ||
|
||
export default class EmptyStatement extends StatementBase { | ||
type: NodeType.tEmptyStatement; | ||
|
||
render(code: MagicString, _options: RenderOptions) { | ||
if (this.parent.type === NodeType.BlockStatement || this.parent.type === NodeType.Program) { | ||
code.remove(this.start, this.end); | ||
} | ||
hasEffects(): boolean { | ||
return false; | ||
} | ||
} |
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
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,27 @@ | ||
import MagicString from 'magic-string'; | ||
import * as NodeType from '../ast/nodes/NodeType'; | ||
import { Node } from '../ast/nodes/shared/Node'; | ||
|
||
export function treeshakeNode(node: Node, code: MagicString, start: number, end: number) { | ||
code.remove(start, end); | ||
if (node.annotations) { | ||
for (const annotation of node.annotations) { | ||
if (annotation.start < start) { | ||
code.remove(annotation.start, annotation.end); | ||
} else { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function removeAnnotations(node: Node, code: MagicString) { | ||
if (!node.annotations && node.parent.type === NodeType.ExpressionStatement) { | ||
node = node.parent as Node; | ||
} | ||
if (node.annotations) { | ||
for (const annotation of node.annotations) { | ||
code.remove(annotation.start, annotation.end); | ||
} | ||
} | ||
} |
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,3 @@ | ||
module.exports = { | ||
description: 'adjust line-break handling when dealing with pure annotations' | ||
}; |
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,37 @@ | ||
const x = 'code'; | ||
console.log('should remain impure'); | ||
|
||
console.log('should remain impure'); | ||
|
||
console.log('code'); | ||
console.log('should remain impure'); | ||
|
||
console.log('code'); | ||
console.log('should remain impure'); | ||
console.log('should remain impure'); | ||
|
||
console.log('code'); | ||
console.log('should remain impure'); | ||
|
||
console.log('code'), | ||
console.log('should remain impure'); | ||
|
||
console.log('code'), | ||
console.log('should remain impure'); | ||
|
||
console.log('should remain impure'); | ||
|
||
console.log('code'); | ||
console.log('should remain impure'); | ||
|
||
console.log('should remain impure'); | ||
|
||
console.log('should remain impure'); | ||
|
||
console.log('code'); | ||
console.log('should remain impure', x); | ||
|
||
|
||
{ | ||
console.log('should remain impure'); | ||
} |
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,3 @@ | ||
const x = 'code';//@__PURE__ | ||
export default x; | ||
console.log('should remain impure'); |
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,45 @@ | ||
/*@__PURE__*/ | ||
(() => {})(); | ||
console.log('should remain impure'); | ||
|
||
console.log('code');//@__PURE__ | ||
(() => {})(); | ||
console.log('should remain impure'); | ||
|
||
console.log('code')/*@__PURE__*/; | ||
(() => {})(); | ||
console.log('should remain impure'); | ||
|
||
(() => {})();//@__PURE__ | ||
(() => {})(); | ||
console.log('should remain impure'); | ||
|
||
console.log('code');/*@__PURE__*///@__PURE__ | ||
/*@__PURE__*/ (() => {})(); | ||
console.log('should remain impure'); | ||
|
||
console.log('code'),//@__PURE__ | ||
(() => {})(),console.log('should remain impure'); | ||
|
||
console.log('code')/*@__PURE__*/, | ||
(() => {})(),console.log('should remain impure'); | ||
|
||
(() => {})(),//@__PURE__ | ||
(() => {})(),console.log('should remain impure'); | ||
|
||
console.log('code');//@__PURE__ | ||
;console.log('should remain impure'); | ||
|
||
/*@__PURE__*/true && console.log('should remain impure'); | ||
|
||
/*@__PURE__*/true ? console.log('should remain impure') : console.log('code'); | ||
|
||
console.log('code');//@__PURE__ | ||
import code from './dep.js'; | ||
|
||
console.log('should remain impure', code); | ||
|
||
/*@__PURE__*/ | ||
if (true) { | ||
console.log('should remain impure'); | ||
} |