-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from raxjs/feat/rename-import
feat(compiler): rename import from pwc
- Loading branch information
Showing
14 changed files
with
383 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
export const basicComponent = ` | ||
<template> | ||
<p>{{this.#name}}</p> | ||
</template> | ||
<script> | ||
export default class CustomElement extends HTMLElement { | ||
#name = ''; | ||
} | ||
</script> | ||
`; | ||
|
||
export const useCustomElementComponent = ` | ||
<template> | ||
<p>hello</p> | ||
</template> | ||
<script> | ||
import { customElement } from 'pwc'; | ||
@customElement('custom-element') | ||
export default class CustomElement extends HTMLElement {} | ||
</script> | ||
`; | ||
|
||
export const useReactiveComponent = ` | ||
<template> | ||
<p>hello</p> | ||
</template> | ||
<script> | ||
import { reactive } from 'pwc'; | ||
export default class CustomElement extends HTMLElement { | ||
@reactive | ||
accessor name = ''; | ||
} | ||
</script> | ||
`; | ||
|
||
export const useReactiveWithAutoAddReactiveComponent = ` | ||
<template> | ||
<p>{{this.#name}}</p> | ||
</template> | ||
<script> | ||
import { reactive } from 'pwc'; | ||
export default class CustomElement extends HTMLElement { | ||
#name = ''; | ||
@reactive | ||
accessor data = ''; | ||
} | ||
</script> | ||
`; | ||
|
||
export const reactiveHasBeenReactiveDecoratedManuallyComponent = ` | ||
<template> | ||
<p>{{this.#name}}</p> | ||
</template> | ||
<script> | ||
import { reactive } from 'pwc'; | ||
export default class CustomElement extends HTMLElement { | ||
@reactive | ||
accessor #name = ''; | ||
} | ||
</script> | ||
`; | ||
|
36 changes: 36 additions & 0 deletions
36
packages/pwc-compiler/__tests__/transforms/customElement.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { parse, compileScript } from '../../src'; | ||
import { basicComponent, useCustomElementComponent } from './components'; | ||
|
||
describe('customElement decorator', () => { | ||
test('It should add customElement decorator', () => { | ||
const { descriptor } = parse(basicComponent); | ||
const result = compileScript(descriptor); | ||
|
||
expect(result.content).toEqual(`import { customElement as __customElement, reactive as __reactive } from \"pwc\"; | ||
@__customElement("custom-element") | ||
export default class CustomElement extends HTMLElement { | ||
@__reactive | ||
accessor #name = ''; | ||
get template() { | ||
return ["\\n <p><!--?pwc_t--></p>\\n", [this.#name]]; | ||
} | ||
}`); | ||
}); | ||
|
||
test('It should not add customElement decorator if there is already customElement manually', () => { | ||
const { descriptor } = parse(useCustomElementComponent); | ||
const result = compileScript(descriptor); | ||
|
||
expect(result.content).toEqual(`import { customElement } from 'pwc'; | ||
@customElement('custom-element') | ||
export default class CustomElement extends HTMLElement { | ||
get template() { | ||
return ["\\n <p>hello</p>\\n", []]; | ||
} | ||
}`); | ||
}); | ||
|
||
}); |
33 changes: 33 additions & 0 deletions
33
packages/pwc-compiler/__tests__/transforms/injectImportPWC.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { parse, compileScript } from '../../src'; | ||
import { basicComponent, useCustomElementComponent, useReactiveComponent, useReactiveWithAutoAddReactiveComponent } from './components'; | ||
|
||
describe('injectImportPWC', () => { | ||
test('It should inject pwc', () => { | ||
const { descriptor } = parse(basicComponent); | ||
const result = compileScript(descriptor); | ||
|
||
expect(result.content).toContain(`import { customElement as __customElement, reactive as __reactive } from \"pwc\";`); | ||
}); | ||
|
||
test('It should not inject import customElement from pwc when imported customElement manually', () => { | ||
const { descriptor } = parse(useCustomElementComponent); | ||
const result = compileScript(descriptor); | ||
|
||
expect(result.content).toContain(`import { customElement } from 'pwc';`); | ||
}); | ||
|
||
test('It should not inject import reactive from pwc when there is no reactive variable in template', () => { | ||
const { descriptor } = parse(useReactiveComponent); | ||
const result = compileScript(descriptor); | ||
|
||
expect(result.content).toContain(`import { reactive, customElement as __customElement } from 'pwc';`); | ||
}); | ||
|
||
|
||
test('It should inject import reactive from pwc even if there is reactive imported manually', () => { | ||
const { descriptor } = parse(useReactiveWithAutoAddReactiveComponent); | ||
const result = compileScript(descriptor); | ||
|
||
expect(result.content).toContain(`import { reactive, customElement as __customElement, reactive as __reactive } from 'pwc';`); | ||
}); | ||
}); |
Oops, something went wrong.