heartao / ts-creator Goto Github PK
View Code? Open in Web Editor NEWA code generator to generate TypeScript code generator from TypeScript code
Home Page: https://ts-creator.js.org/
License: MIT License
A code generator to generate TypeScript code generator from TypeScript code
Home Page: https://ts-creator.js.org/
License: MIT License
Hi.
Currently I am fiddling around writing my own custom typescript transformer. In this context I also discovered this package.
I am wondering how or if ts-creator
could be used to e.g. insert a node into the ast.
I understand that I get the ast representation with the creator
function of the package. But I do not understand how I can use the returned string directly to e.g. insert a node into the ast.
Currently I just use the package as an helper to see what the exact ast representation would be. But it would be really cool if this string could somehow be used directly.
Therefore I just wanted to ask if someone has an idea. I appreciate any help.
Thanks in advance,
Lukas
upstream: prettier/prettier#5760
upstream: microsoft/TypeScript#29341
please description yor bug infomation, error snippets, or screenshot
import('./a')
While this library looks really cool, it's really hard to understand how to use it.
there are only 8 usages of this lib on github (half of them - this repo):
https://github.com/search?l=TypeScript&q=creator+ts-creator&type=Code
import creator from 'ts-creator'
const generatedFactoryCode = creator(`const foo = "your code here"`)
This generates a string?
I was hoping the result to be a list of ts.Statement
, and I'm not sure how to convert those? Eval?
import { transformSourceFile } from 'ts-creator'
declare const file: ts.SourceFile
const factoryFile = transformSourceFile(file)
It's not clear what this does, what's factoryFile, and why does it need to take a source file?
import { transformNode } from 'ts-creator'
declare const node: ts.Expression
const factoryNode = transformNode(node)
Same as above. It promises some kind of transformation, but it's not clear how to use it.
https://ts-creator.js.org/ - The playground it cool, but it comes empty, and there are no samples.
If you look at the typescript playground it comes pre-populated with code, and has lots of samples that people can play with to better understand how things work.
I'd be happy to send a PR for some of those things, but may need some clarification first.
Line 20 in 42905da
TypeScript has updated their api
and most of the generated code is marked deprecated
I currently run it like this:
ts-creator input.ts --no-color | \
sed 's/ts.create/ts.factory.create/g' | \
sed 's/createParameter/createParameterDeclaration/g' | \
sed 's/createCall/createCallExpression/g' | \
sed 's/createPropertyAccess/createPropertyAccessExpression/g' | \
sed 's/createReturn/createReturnStatement/g' | \
sed 's/createElementAccess/createElementAccessExpression/g' | \
sed 's/createSpread/createSpreadElement/g'
But I'll bet there are many more changes...
upstream: microsoft/TypeScript#29891
type Factory<T extends Node> = Record<T["kind"], (node: T) => T>
type ListFactory<T extends Node> = Record<T["kind"], (node: T) =>T[]>
const a = 1;
{
[ts.SyntaxKind.Identifier]: (id: ts.Identifier) => {
// match id is 'a'
// ...
return ts.createIdentifier(id.text.toUpperCase())
}
}
to
ts.createVariableStatement(
undefined,
ts.createVariableDeclarationList(
[
ts.createVariableDeclaration(
ts.createIdentifier('A'),
undefined,
ts.createNumericLiteral('1')
)
],
ts.NodeFlags.Const
)
)
interface Foo {
a: never
}
{
[ts.SyntaxKind.PropertySignature]: (p: ts.PropertySignature) => {
// match p is 'a: never'
// ...
return [
ts.createPropertySignature(
undefined,
ts.createIdentifier('a'),
undefined,
ts.createKeywordTypeNode(ts.SyntaxKind.NumberKeyword),
undefined
),
ts.createPropertySignature(
undefined,
ts.createIdentifier('b'),
undefined,
ts.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
undefined
)
]
}
}
to
interface Foo {
a: number
b: string
}
Thanks!
please description yor bug infomation, error snippets, or screenshot
also let me know about your environment, OS info, node/npm version or other information
[,,a] = getArr()
I honestly love this package! I use it heavily to develop things like macro-ts
. There's just an annoying security bug that's always popping up, and even though this is just a dev dependency I'd love for it to go away!
Can you just run npm update
and then republish a patch version? Thanks!
Here's the results of running npm audit
in a package that uses yours:
$ npm audit
=== npm audit security report ===
┌──────────────────────────────────────────────────────────────────────────────┐
│ Manual Review │
│ Some vulnerabilities require your attention to resolve │
│ │
│ Visit https://go.npm.me/audit-guide for additional guidance │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low │ Prototype Pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ yargs-parser │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ >=13.1.2 <14.0.0 || >=15.0.1 <16.0.0 || >=18.1.2 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ ts-creator [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ ts-creator > yargs > yargs-parser │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://npmjs.com/advisories/1500 │
└───────────────┴──────────────────────────────────────────────────────────────┘
found 1 low severity vulnerability in 213 scanned packages
1 vulnerability requires manual review. See the full report for details.
upstream: microsoft/TypeScript#29425
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.