UNPKG

2.8 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt
7 * The complete set of authors may be found at
8 * http://polymer.github.io/AUTHORS.txt
9 * The complete set of contributors may be found at
10 * http://polymer.github.io/CONTRIBUTORS.txt
11 * Code distributed by Google as part of the polymer project is also
12 * subject to an additional IP rights grant found at
13 * http://polymer.github.io/PATENTS.txt
14 */
15Object.defineProperty(exports, "__esModule", { value: true });
16const babelCore = require("@babel/core");
17const stripIndent = require("strip-indent");
18const chai_1 = require("chai");
19const babel_plugin_import_meta_1 = require("../babel-plugin-import-meta");
20suite('babel-plugin-import-meta', () => {
21 test('transforms import.meta', () => {
22 const input = stripIndent(`
23 console.log(import.meta);
24 console.log(import.meta.url);
25 `);
26 const expected = stripIndent(`
27 import * as meta from 'meta';
28 console.log(meta);
29 console.log(meta.url);
30 `);
31 const result = babelCore.transform(input, { plugins: [babel_plugin_import_meta_1.rewriteImportMeta] }).code;
32 chai_1.assert.equal(result.trim(), expected.trim());
33 });
34 test('does not transform non-meta property', () => {
35 const input = stripIndent(`
36 console.log(foo.import.meta);
37 `);
38 const expected = stripIndent(`
39 console.log(foo.import.meta);
40 `);
41 const result = babelCore.transform(input, { plugins: [babel_plugin_import_meta_1.rewriteImportMeta] }).code;
42 chai_1.assert.equal(result.trim(), expected.trim());
43 });
44 test('picks a unique import name', () => {
45 const input = stripIndent(`
46 const meta = 'foo';
47 console.log(import.meta);
48 `);
49 const expected = stripIndent(`
50 import * as _meta from 'meta';
51 const meta = 'foo';
52 console.log(_meta);
53 `);
54 const result = babelCore.transform(input, { plugins: [babel_plugin_import_meta_1.rewriteImportMeta] }).code;
55 chai_1.assert.equal(result.trim(), expected.trim());
56 });
57 test('picks a unique import name x2', () => {
58 const input = stripIndent(`
59 const meta = 'foo';
60 const _meta = 'bar';
61 console.log(import.meta);
62 `);
63 const expected = stripIndent(`
64 import * as _meta2 from 'meta';
65 const meta = 'foo';
66 const _meta = 'bar';
67 console.log(_meta2);
68 `);
69 const result = babelCore.transform(input, { plugins: [babel_plugin_import_meta_1.rewriteImportMeta] }).code;
70 chai_1.assert.equal(result.trim(), expected.trim());
71 });
72});
73//# sourceMappingURL=babel-plugin-import-meta_test.js.map
\No newline at end of file