Coder Social home page Coder Social logo

ts-creator's People

Contributors

angrypowman avatar blainehansen avatar hairyrabbit avatar kingwl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ts-creator's Issues

Question: ts-creator & TypeScript transformer

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

[Feature] Better docs

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.

Update to new factory interfaces

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...

Outside value Support

Syntax node(list) factory

type Factory<T extends Node> = Record<T["kind"], (node: T) => T>  
type ListFactory<T extends Node> = Record<T["kind"], (node: T) =>T[]> 

Signal node factory

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
    )
)

Multi node factory

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
}

[Bug] OmitElement support

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()

[Bug] Outdated Dependencies

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.