Skip to content

Commit af377fc

Browse files
committed
refactor: fix the literals a bit
Also remove the usage of common-tags everywhere.
1 parent 6b91f53 commit af377fc

File tree

14 files changed

+796
-826
lines changed

14 files changed

+796
-826
lines changed

package-lock.json

Lines changed: 616 additions & 684 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"homepage": "https://github.com/angular/devkit",
4343
"dependencies": {
4444
"@ngtools/json-schema": "^1.0.9",
45-
"@types/common-tags": "^1.2.4",
4645
"@types/glob": "^5.0.29",
4746
"@types/istanbul": "^0.4.29",
4847
"@types/jasmine": "^2.5.47",
@@ -52,7 +51,6 @@
5251
"@types/source-map": "^0.5.0",
5352
"@types/webpack": "^3.0.2",
5453
"@types/webpack-sources": "^0.1.3",
55-
"common-tags": "^1.3.1",
5654
"conventional-changelog": "^1.1.0",
5755
"glob": "^7.0.3",
5856
"istanbul": "^0.4.5",

packages/angular_devkit/build_optimizer/src/build-optimizer/build-optimizer_spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { oneLine, stripIndent } from 'common-tags';
8+
import { tags } from '@angular-devkit/core';
99
import { RawSourceMap } from 'source-map';
1010
import { buildOptimizer } from './build-optimizer';
1111

@@ -18,7 +18,7 @@ describe('build-optimizer', () => {
1818

1919
describe('basic functionality', () => {
2020
it('applies class-fold, scrub-file and prefix-functions', () => {
21-
const input = stripIndent`
21+
const input = tags.stripIndent`
2222
${imports}
2323
var __extends = (this && this.__extends) || function (d, b) {
2424
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
@@ -37,7 +37,7 @@ describe('build-optimizer', () => {
3737
Clazz.ctorParameters = function () { return [{type: Injector}]; };
3838
`;
3939
// tslint:disable:max-line-length
40-
const output = oneLine`
40+
const output = tags.oneLine`
4141
/** PURE_IMPORTS_START _angular_core,tslib PURE_IMPORTS_END */
4242
${imports}
4343
import { __extends } from "tslib";
@@ -52,12 +52,12 @@ describe('build-optimizer', () => {
5252

5353
const inputFilePath = '/node_modules/@angular/core/@angular/core.es5.js';
5454
const boOutput = buildOptimizer({ content: input, inputFilePath });
55-
expect(oneLine`${boOutput.content}`).toEqual(output);
55+
expect(tags.oneLine`${boOutput.content}`).toEqual(output);
5656
expect(boOutput.emitSkipped).toEqual(false);
5757
});
5858

5959
it('doesn\'t process files without decorators/ctorParameters/outside Angular', () => {
60-
const input = oneLine`
60+
const input = tags.oneLine`
6161
var Clazz = (function () { function Clazz() { } return Clazz; }());
6262
${staticProperty}
6363
`;
@@ -70,26 +70,26 @@ describe('build-optimizer', () => {
7070
it('supports es2015 modules', () => {
7171
// prefix-functions would add PURE_IMPORTS_START and PURE to the super call.
7272
// This test ensures it isn't applied to es2015 modules.
73-
const output = oneLine`
73+
const output = tags.oneLine`
7474
import { Injectable } from '@angular/core';
7575
class Clazz extends BaseClazz { constructor(e) { super(e); } }
7676
`;
77-
const input = stripIndent`
77+
const input = tags.stripIndent`
7878
${output}
7979
Clazz.ctorParameters = () => [ { type: Injectable } ];
8080
`;
8181

8282
const inputFilePath = '/node_modules/@angular/core/@angular/core.js';
8383
const boOutput = buildOptimizer({ content: input, inputFilePath });
84-
expect(oneLine`${boOutput.content}`).toEqual(output);
84+
expect(tags.oneLine`${boOutput.content}`).toEqual(output);
8585
expect(boOutput.emitSkipped).toEqual(false);
8686
});
8787
});
8888

8989

9090
describe('resilience', () => {
9191
it('doesn\'t process files with invalid syntax by default', () => {
92-
const input = oneLine`
92+
const input = tags.oneLine`
9393
))))invalid syntax
9494
${clazz}
9595
Clazz.decorators = [ { type: Injectable } ];
@@ -101,7 +101,7 @@ describe('build-optimizer', () => {
101101
});
102102

103103
it('throws on files with invalid syntax in strict mode', () => {
104-
const input = oneLine`
104+
const input = tags.oneLine`
105105
))))invalid syntax
106106
${clazz}
107107
Clazz.decorators = [ { type: Injectable } ];
@@ -137,7 +137,7 @@ describe('build-optimizer', () => {
137137
});
138138

139139
describe('sourcemaps', () => {
140-
const transformableInput = oneLine`
140+
const transformableInput = tags.oneLine`
141141
${imports}
142142
${clazz}
143143
${decorators}
@@ -154,11 +154,11 @@ describe('build-optimizer', () => {
154154
});
155155

156156
it('doesn\'t produce sourcemaps when emitting was skipped', () => {
157-
const ignoredInput = oneLine`
157+
const ignoredInput = tags.oneLine`
158158
var Clazz = (function () { function Clazz() { } return Clazz; }());
159159
${staticProperty}
160160
`;
161-
const invalidInput = oneLine`
161+
const invalidInput = tags.oneLine`
162162
))))invalid syntax
163163
${clazz}
164164
Clazz.decorators = [ { type: Injectable } ];

packages/angular_devkit/build_optimizer/src/purify/purify_spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,77 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { oneLine, stripIndent } from 'common-tags';
8+
import { tags } from '@angular-devkit/core';
99
import { purify } from './purify';
1010

1111
// tslint:disable:max-line-length
1212
describe('purify', () => {
1313
it('prefixes safe imports with /*@__PURE__*/', () => {
14-
const input = stripIndent`
14+
const input = tags.stripIndent`
1515
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_rxjs_Subject__ = __webpack_require__("EEr4");
1616
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_http__ = __webpack_require__(72);
1717
/** PURE_IMPORTS_START rxjs_Subject,_angular_http PURE_IMPORTS_END */
1818
`;
19-
const output = stripIndent`
19+
const output = tags.stripIndent`
2020
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_rxjs_Subject__ = /*@__PURE__*/__webpack_require__("EEr4");
2121
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_http__ = /*@__PURE__*/__webpack_require__(72);
2222
/** PURE_IMPORTS_START rxjs_Subject,_angular_http PURE_IMPORTS_END */
2323
`;
2424

25-
expect(oneLine`${purify(input)}`).toEqual(oneLine`${output}`);
25+
expect(tags.oneLine`${purify(input)}`).toEqual(tags.oneLine`${output}`);
2626
});
2727

2828
it('prefixes safe default imports with /*@__PURE__*/', () => {
29-
const input = stripIndent`
29+
const input = tags.stripIndent`
3030
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_rxjs_Subject__ = __webpack_require__("rlar");
3131
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_rxjs_Subject___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_rxjs_Subject__);
3232
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_zone_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_zone_js__);
3333
/** PURE_IMPORTS_START rxjs_Subject,zone_js PURE_IMPORTS_END */
3434
`;
35-
const output = stripIndent`
35+
const output = tags.stripIndent`
3636
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_rxjs_Subject__ = /*@__PURE__*/__webpack_require__("rlar");
3737
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4_rxjs_Subject___default = /*@__PURE__*/__webpack_require__.n(__WEBPACK_IMPORTED_MODULE_4_rxjs_Subject__);
3838
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_zone_js___default = /*@__PURE__*/__webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_zone_js__);
3939
/** PURE_IMPORTS_START rxjs_Subject,zone_js PURE_IMPORTS_END */
4040
`;
4141

42-
expect(oneLine`${purify(input)}`).toEqual(oneLine`${output}`);
42+
expect(tags.oneLine`${purify(input)}`).toEqual(tags.oneLine`${output}`);
4343
});
4444

4545
it('prefix createComponentFactory and createNgModuleFactory function calls', () => {
46-
const input = stripIndent`
46+
const input = tags.stripIndent`
4747
var AppComponentNgFactory = __WEBPACK_IMPORTED_MODULE_1__angular_core__["I" /* ɵccf */]('app-root');
4848
var AppModuleNgFactory = __WEBPACK_IMPORTED_MODULE_1__angular_core__["I" /* ɵcmf */]('app-root');
4949
var SelectComponentNgFactory = select_component_ngfactory___WEBPACK_IMPORTED_MODULE_0__angular_core__["U" /* ɵccf */]('aio-select');
5050
`;
51-
const output = stripIndent`
51+
const output = tags.stripIndent`
5252
var AppComponentNgFactory = /*@__PURE__*/__WEBPACK_IMPORTED_MODULE_1__angular_core__["I" /* ɵccf */]('app-root');
5353
var AppModuleNgFactory = /*@__PURE__*/__WEBPACK_IMPORTED_MODULE_1__angular_core__["I" /* ɵcmf */]('app-root');
5454
var SelectComponentNgFactory = /*@__PURE__*/select_component_ngfactory___WEBPACK_IMPORTED_MODULE_0__angular_core__["U" /* ɵccf */]('aio-select');
5555
`;
5656

57-
expect(oneLine`${purify(input)}`).toEqual(oneLine`${output}`);
57+
expect(tags.oneLine`${purify(input)}`).toEqual(tags.oneLine`${output}`);
5858
});
5959

6060
it('should prefix createRendererType2 function calls', () => {
61-
const input = stripIndent`
61+
const input = tags.stripIndent`
6262
var RenderType_MdOption = index_ngfactory___WEBPACK_IMPORTED_MODULE_0__angular_core__["W" /* ɵcrt */]({ encapsulation: 2, styles: styles_MdOption});
6363
`;
64-
const output = stripIndent`
64+
const output = tags.stripIndent`
6565
var RenderType_MdOption = /*@__PURE__*/index_ngfactory___WEBPACK_IMPORTED_MODULE_0__angular_core__["W" /* ɵcrt */]({ encapsulation: 2, styles: styles_MdOption});
6666
`;
6767

68-
expect(oneLine`${purify(input)}`).toEqual(oneLine`${output}`);
68+
expect(tags.oneLine`${purify(input)}`).toEqual(tags.oneLine`${output}`);
6969
});
7070

7171
it('prefix module statements', () => {
72-
const input = stripIndent`
72+
const input = tags.stripIndent`
7373
var AppModuleNgFactory = new __WEBPACK_IMPORTED_MODULE_1__angular_core__["I" /* NgModuleFactory */];
7474
`;
75-
const output = stripIndent`
75+
const output = tags.stripIndent`
7676
var AppModuleNgFactory = /*@__PURE__*/new __WEBPACK_IMPORTED_MODULE_1__angular_core__["I" /* NgModuleFactory */];
7777
`;
7878

79-
expect(oneLine`${purify(input)}`).toEqual(oneLine`${output}`);
79+
expect(tags.oneLine`${purify(input)}`).toEqual(tags.oneLine`${output}`);
8080
});
8181
});

packages/angular_devkit/build_optimizer/src/transforms/class-fold_spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { oneLine, stripIndent } from 'common-tags';
8+
import { tags } from '@angular-devkit/core';
99
import { transformJavascript } from '../helpers/transform-javascript';
1010
import { getFoldFileTransformer } from './class-fold';
1111

@@ -16,31 +16,31 @@ const transform = (content: string) => transformJavascript(
1616
describe('class-fold', () => {
1717
it('folds static properties into class', () => {
1818
const staticProperty = 'Clazz.prop = 1;';
19-
const input = stripIndent`
19+
const input = tags.stripIndent`
2020
var Clazz = (function () { function Clazz() { } return Clazz; }());
2121
${staticProperty}
2222
`;
23-
const output = stripIndent`
23+
const output = tags.stripIndent`
2424
var Clazz = (function () { function Clazz() { }
2525
${staticProperty} return Clazz; }());
2626
`;
2727

28-
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
28+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
2929
});
3030

3131
it('folds multiple static properties into class', () => {
3232
const staticProperty = 'Clazz.prop = 1;';
3333
const anotherStaticProperty = 'Clazz.anotherProp = 2;';
34-
const input = stripIndent`
34+
const input = tags.stripIndent`
3535
var Clazz = (function () { function Clazz() { } return Clazz; }());
3636
${staticProperty}
3737
${anotherStaticProperty}
3838
`;
39-
const output = stripIndent`
39+
const output = tags.stripIndent`
4040
var Clazz = (function () { function Clazz() { }
4141
${staticProperty} ${anotherStaticProperty} return Clazz; }());
4242
`;
4343

44-
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
44+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
4545
});
4646
});

packages/angular_devkit/build_optimizer/src/transforms/import-tslib_spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { oneLine, stripIndent } from 'common-tags';
8+
import { tags } from '@angular-devkit/core';
99
import { transformJavascript } from '../helpers/transform-javascript';
1010
import { getImportTslibTransformer, testImportTslib } from './import-tslib';
1111

@@ -15,24 +15,24 @@ const transform = (content: string) => transformJavascript(
1515

1616
describe('import-tslib', () => {
1717
it('replaces __extends', () => {
18-
const input = stripIndent`
18+
const input = tags.stripIndent`
1919
var __extends = (this && this.__extends) || function (d, b) {
2020
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
2121
function __() { this.constructor = d; }
2222
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2323
};
2424
`;
25-
const output = stripIndent`
25+
const output = tags.stripIndent`
2626
import { __extends } from "tslib";
2727
`;
2828

2929
expect(testImportTslib(input)).toBeTruthy();
30-
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
30+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
3131
});
3232

3333
it('replaces __decorate', () => {
3434
// tslint:disable:max-line-length
35-
const input = stripIndent`
35+
const input = tags.stripIndent`
3636
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3737
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3838
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -41,59 +41,59 @@ describe('import-tslib', () => {
4141
};
4242
`;
4343
// tslint:enable:max-line-length
44-
const output = stripIndent`
44+
const output = tags.stripIndent`
4545
import { __decorate } from "tslib";
4646
`;
4747

4848
expect(testImportTslib(input)).toBeTruthy();
49-
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
49+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
5050
});
5151

5252
it('replaces __metadata', () => {
5353
// tslint:disable:max-line-length
54-
const input = stripIndent`
54+
const input = tags.stripIndent`
5555
var __metadata = (this && this.__metadata) || function (k, v) {
5656
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
5757
};
5858
`;
5959
// tslint:enable:max-line-length
60-
const output = stripIndent`
60+
const output = tags.stripIndent`
6161
import { __metadata } from "tslib";
6262
`;
6363

6464
expect(testImportTslib(input)).toBeTruthy();
65-
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
65+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
6666
});
6767

6868
it('replaces __param', () => {
69-
const input = stripIndent`
69+
const input = tags.stripIndent`
7070
var __param = (this && this.__param) || function (paramIndex, decorator) {
7171
return function (target, key) { decorator(target, key, paramIndex); }
7272
};
7373
`;
7474

75-
const output = stripIndent`
75+
const output = tags.stripIndent`
7676
import { __param } from "tslib";
7777
`;
7878

7979
expect(testImportTslib(input)).toBeTruthy();
80-
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
80+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
8181
});
8282

8383
it('replaces uses "require" instead of "import" on CJS modules', () => {
84-
const input = stripIndent`
84+
const input = tags.stripIndent`
8585
var __extends = (this && this.__extends) || function (d, b) {
8686
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
8787
function __() { this.constructor = d; }
8888
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
8989
};
9090
exports.meaning = 42;
9191
`;
92-
const output = stripIndent`
92+
const output = tags.stripIndent`
9393
var __extends = /*@__PURE__*/ require("tslib").__extends;
9494
exports.meaning = 42;
9595
`;
9696

97-
expect(oneLine`${transform(input)}`).toEqual(oneLine`${output}`);
97+
expect(tags.oneLine`${transform(input)}`).toEqual(tags.oneLine`${output}`);
9898
});
9999
});

0 commit comments

Comments
 (0)