-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee9cd5c
commit 003e9ea
Showing
7 changed files
with
161 additions
and
80 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 |
---|---|---|
@@ -1,60 +1,129 @@ | ||
import prettier from 'prettier'; | ||
import tsParser from 'prettier/parser-typescript'; | ||
|
||
export const PREVIEW_CODE = prettier.format( | ||
` | ||
@decorator({ | ||
property: 'test' | ||
}) | ||
class Test { | ||
private readonly property: string = ''; | ||
readonly property2: number[] = [1, 2, 3]; | ||
constructor( | ||
private readonly property3: symbol | ||
) { | ||
super(); | ||
} | ||
get getter() { | ||
return this.property; | ||
} | ||
method(): void { | ||
return this.property2.map(el => el * 2); | ||
} | ||
} | ||
function Counter() { | ||
const [count, setCount] = createSignal(0); | ||
const increment = () => setCount(count => count + 1); | ||
return ( | ||
<button type='button' onClick={increment}> | ||
{count()} | ||
</button> | ||
); | ||
} | ||
enum Enum { | ||
0, | ||
1, | ||
3, | ||
4 = '4', | ||
5 = '5' | ||
} | ||
interface User { | ||
username: string; | ||
firstName?: string; | ||
lastName: string; | ||
} | ||
type BaseUser = Pick<User, 'firstName' | 'lastName'>; | ||
`, | ||
{ | ||
parser: 'typescript', | ||
plugins: [tsParser], | ||
}, | ||
); | ||
export const PREVIEW_CODE = | ||
'var globalVar;\n' + | ||
'/**\n' + | ||
' * Constructor for AjaxRequest class\n' + | ||
' * @param {string} url the url for the request<p/>\n' + | ||
' */\n' + | ||
'function AjaxRequest(url) {\n' + | ||
' function local() {}\n' + | ||
' var urls = [ "www.cnn.com", 5, globalVar];\n' + | ||
' this.request = new XMLHttpRequest();\n' + | ||
' url = url.replace(/^\\s*(.*)/, "$1"); // skip leading whitespace\n' + | ||
' /* check the url to be in urls */\n' + | ||
' this.foo = new function() {};\n' + | ||
' foo();\n' + | ||
' var hello = () => console.log("hello")}\n' + | ||
'\n' + | ||
'@decorator()\n' + | ||
'class NameClass {\n' + | ||
'}\n' + | ||
'declare module name{\n' + | ||
' declare export var exportedVar: string;\n' + | ||
' declare export function exportedFunction(): void;\n' + | ||
' declare export class ExportedClass {}\n' + | ||
'}\n' + | ||
'interface MyInterface { }\n' + | ||
'type FooBarAlias = string;\n' + | ||
"var html =`<div title='HTML injection'>Injected language fragment</div>`;\n" + | ||
'var x: MyInterface, y: string, z: FooBarAlias;\n' + | ||
'module ModuleValidator {\n' + | ||
' import checkChars = CharUtils.notWhiteSpace;\n' + | ||
' export interface HasValidator<T> {\n' + | ||
' validateValue():Boolean;\n' + | ||
' }\n' + | ||
'\n' + | ||
' type FooBarAlias = string;\n' + | ||
'\n' + | ||
' @decorator()\n' + | ||
' class HasValidator implements HasValidator<String> {\n' + | ||
' /* Processed values */\n' + | ||
' static validatedValue:Array<String> = ["", "aa"];\n' + | ||
' private myValue:String;\n' + | ||
'\n' + | ||
' /**\n' + | ||
' * Constructor for class\n' + | ||
' * @param valueParameter Value for <i>validation</i>\n' + | ||
' */\n' + | ||
' constructor(valueParameter: String) {\n' + | ||
' this.myValue = valueParameter;\n' + | ||
' HasValidator.validatedValue.push(value);\n' + | ||
' }\n' + | ||
'\n' + | ||
' public validateValue():Boolean {\n' + | ||
' var resultValue:Boolean = checkChars(this.myValue);\n' + | ||
' return resultValue;\n' + | ||
' }\n' + | ||
'\n' + | ||
' static createInstance(valueParameter: string): HasValidator {\n' + | ||
' return new HasValidator(valueParameter);\n' + | ||
' }\n' + | ||
' }\n' + | ||
'\n' + | ||
' function globalFunction<TypeParameter>(value:TypeParameter) { //global function\n' + | ||
' return 42;\n' + | ||
' }\n' + | ||
' declare var declareUrl;\n' + | ||
' var hello = () => console.log("hello");\n' + | ||
' HasValidator.createInstance(varUrl).validateValue();\n' + | ||
' function acceptsUnion(s: string | number) {\n' + | ||
' if (typeof s === "string") {\n' + | ||
' s\n' + | ||
' }\n' + | ||
' }\n' + | ||
' enum EnumName {\n' + | ||
' EnumMember\n' + | ||
' }}' + | ||
"import _ from 'lodash';\n" + | ||
"export declare interface MyInterface from './myClass';\n" + | ||
'export default MyClass;\n' + | ||
'\n' + | ||
'type MyFoo = MyInterface;\n' + | ||
'type Types = keyof typeof types;\n' + | ||
'\n' + | ||
'class MyType extends AbstractClass {\n' + | ||
' private field: string;\n' + | ||
' protected value: number;\n' + | ||
' public num = 10;\n' + | ||
'\n' + | ||
' static foo(): unknown {}\n' + | ||
' get hello(): any {}\n' + | ||
' set hello(v): void {}\n' + | ||
'\n' + | ||
' method() {\n' + | ||
' var x = 10;\n' + | ||
' this.x = null;\n' + | ||
' if (x === undefined) {\n' + | ||
" console.log('foo');\n" + | ||
" window.alert('foo');\n" + | ||
' debugger;\n' + | ||
' return false;\n' + | ||
' }\n' + | ||
' return true;\n' + | ||
' }\n' + | ||
'\n' + | ||
' async function promise() {\n' + | ||
' try {\n' + | ||
' const res = await myCall();\n' + | ||
' yield 10;\n' + | ||
' } catch (e as Error) {\n' + | ||
' throw new Error("invalid");\n' + | ||
' } finally {\n' + | ||
' for (let elem of array) {\n' + | ||
' if (elem instanceof SomeClass || elem typeof SomeClass) return false;\n' + | ||
' }\n' + | ||
' }\n' + | ||
'\n' + | ||
' return true;\n' + | ||
' }\n' + | ||
'}\n' + | ||
'\n' + | ||
'enum MyEnum {\n' + | ||
' UP = 1,\n' + | ||
' DOWN = 2\n' + | ||
'}\n' + | ||
'\n' + | ||
'export default SomeClass;\n' + | ||
'module.exports = foo;'; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.