Skip to content

Commit

Permalink
refactor: replace var by const
Browse files Browse the repository at this point in the history
  • Loading branch information
kcmr committed Dec 31, 2020
1 parent 20a195e commit c2d9e2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ function run(source: string, options?: Partial<PluginOptions>, ...plugins_: any[
}

it('smoke', () => {
const result = run(`var foo = 1`);
expect(result).toEqual(`var foo = 1;`);
const result = run(`const foo = 1`);
expect(result).toEqual(`const foo = 1;`);
});

it('get styles single', () => {
Expand All @@ -27,7 +27,7 @@ it('get styles single', () => {
},
);
expect(result).not.toEqual(expect.stringMatching(`import style from 'style.css'`));
expect(result).toEqual(expect.stringMatching('var style = "a {}";'));
expect(result).toEqual(expect.stringMatching('const style = "a {}";'));
});

it('styles with postcss option', () => {
Expand All @@ -41,7 +41,7 @@ it('styles with postcss option', () => {
},
);
expect(result).toEqual(
`var style = "a { position: absolute; top: 50%; transform: translateY(-50%) }";`,
`const style = "a { position: absolute; top: 50%; transform: translateY(-50%) }";`,
);
});

Expand All @@ -55,8 +55,8 @@ it('get styles array', () => {
readFileSync: (file: string) => `.${file.slice(-6, -4)} {}`,
},
);
expect(result).toEqual(expect.stringMatching('var style1 = ".p1 {}'));
expect(result).toEqual(expect.stringMatching('var style2 = ".p2 {}'));
expect(result).toEqual(expect.stringMatching('const style1 = ".p1 {}'));
expect(result).toEqual(expect.stringMatching('const style2 = ".p2 {}'));
});

it('side effect import', () => {
Expand Down Expand Up @@ -94,11 +94,11 @@ it('tagged template expression', () => {
},
);
expect(result).toEqual(expect.stringMatching('import { css as _css } from "lit-element"'));
expect(result).toEqual(expect.stringMatching('var style = _css`a {}`'));
expect(result).toEqual(expect.stringMatching('const style = _css`a {}`'));
expect(result).toEqual(
expect.stringMatching(stripIndents`
import { css as _css } from "lit-element";
var style = _css\`a {}\`;
const style = _css\`a {}\`;
`),
);
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function ({ types: t }: typeof babel, options: PluginOptions): Pl
variableDeclaratorInit = t.stringLiteral(cssContent);
}
path.replaceWith(
t.variableDeclaration('var', [
t.variableDeclaration('const', [
t.variableDeclarator(t.identifier(defaultImportName), variableDeclaratorInit),
]),
);
Expand Down

0 comments on commit c2d9e2b

Please sign in to comment.