Skip to content

Commit 0137a67

Browse files
Merge branch 'master' of github.com:ampproject/animations
2 parents 58b8bd6 + 9181683 commit 0137a67

File tree

4 files changed

+228
-200
lines changed

4 files changed

+228
-200
lines changed

compile/remove-empty-space.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright 2020 The AMP HTML Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS-IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const MagicString = require('magic-string');
18+
const walk = require('acorn-walk');
19+
20+
export function removeEmptySpace() {
21+
return {
22+
name: 'remove-empty-space',
23+
transform(code) {
24+
const source = new MagicString(code);
25+
const program = this.parse(code, { ranges: true });
26+
27+
walk.simple(program, {
28+
TemplateLiteral(node) {
29+
const [start, end] = node.range;
30+
let literalValue = code.substring(start, end);
31+
literalValue = literalValue
32+
.replace(/\) \{/g, '){')
33+
.replace(/, /g, ',')
34+
.replace(/ = /g, '=')
35+
.replace(/\t/g, '')
36+
.replace(/[ ]{2,}/g, '')
37+
.replace(/\n/g, '');
38+
source.overwrite(start, end, literalValue);
39+
},
40+
});
41+
42+
return {
43+
code: source.toString(),
44+
map: source.generateMap(),
45+
};
46+
},
47+
};
48+
}

0 commit comments

Comments
 (0)