Skip to content

Commit e1a00fb

Browse files
author
Osama Jandali
committed
Move annotation to CallExpression
- Instead of annotating from templateLiterals, now the annotation is from CallExpression. - useUglifyPure is now false by default to help getting the reviewing stage and then we could make it true again after updating the snapshots.
1 parent bfe647f commit e1a00fb

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import annotateAsPure from "@babel/helper-annotate-as-pure"
2+
13
import minify from './visitors/minify'
24
import displayNameAndId from './visitors/displayNameAndId'
35
import templateLiterals from './visitors/templateLiterals'
46
import assignStyledRequired from './visitors/assignStyledRequired'
57
import { noParserImportDeclaration, noParserRequireCallExpression } from './visitors/noParserImport'
8+
import { useUglifyPure } from './utils/options'
69

710
export default function({ types: t }) {
811
return {
@@ -11,6 +14,11 @@ export default function({ types: t }) {
1114
noParserImportDeclaration(path, state)
1215
},
1316
CallExpression(path, state) {
17+
if(useUglifyPure(state)){
18+
if(path.parent.type == 'VariableDeclarator' || path.parent.type == 'TaggedTemplateExpression'){
19+
annotateAsPure(path.node)
20+
}
21+
}
1422
noParserRequireCallExpression(path, state)
1523
},
1624
TaggedTemplateExpression(path, state) {

src/utils/options.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export const useFileName = (state) =>getOption(state, 'fileName')
88
export const useMinify = (state) => getOption(state, 'minify')
99
export const useCSSPreprocessor = (state) => getOption(state, 'preprocess', false) // EXPERIMENTAL
1010
export const useTranspileTemplateLiterals = (state) => getOption(state, 'transpileTemplateLiterals')
11-
export const useUglifyPure = (state) => getOption(state, 'uglifyPure')
11+
export const useUglifyPure = (state) => getOption(state, 'uglifyPure', false)

src/visitors/templateLiterals/index.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
useTranspileTemplateLiterals,
44
useUglifyPure
55
} from '../../utils/options'
6-
import annotateAsPure from "@babel/helper-annotate-as-pure";
76

87
import preprocess from './preprocess'
98
import transpile from './transpile'
@@ -16,10 +15,4 @@ export default (path, state) => {
1615
} else if (useTranspileTemplateLiterals(state)) {
1716
transpile(path, state)
1817
}
19-
20-
// add uglify pure (/*#__PURE__*/) comment before function calls
21-
if(useUglifyPure(state)){
22-
path.node.leadingComments = path.node.leadingComments || []
23-
annotateAsPure(path)
24-
}
2518
}

0 commit comments

Comments
 (0)