MengLinMaker / eslint-plugin-runtime-compat

Eslint check JS runtime conpatability issues. Inspired by eslint-plugin-compat and runtime-compat-data.
MIT License
3 stars 0 forks source link

feat: track target nodes with TypeScript AST #44

Open MengLinMaker opened 6 days ago

MengLinMaker commented 6 days ago

Useful tool for exploring TypeScript AST:

TS AST viewer for this example:

const _Cache = Cache
const cache = new _Cache()
cache.add("test.html")

const keys = cache.keys()
const _keys =  new Cache().keys()
_keys.then((request) =>{
    const len = request.length
})

Types to infer

Instance

VariableDeclaration + PropertyAccessExpression:

Method

PropertyAccessExpression:


Types to ignore

Class

NewExpression + VariableDeclaration:

MengLinMaker commented 5 days ago

Potential solution

Depth here refers to the depth in compat data json.

Depth 1

Class instantiations

  1. Detect NewExpression Node of Type <Class>

Note: This will detect any alias to class. But will fail when a custom class name is same as API class.

Global instances

  1. Detect Identifier Node of Symbol <instance>

Depth 2

Class property access

  1. Detect any Node of Type <Class>
  2. If parent Node is PropertyAccessExpression and Symbol <Property>

Note: Need to remove _static from <Property>_static

Limitations:

Todo:

Depth 2

Event listeners - won't be used on server side?

Depth 3 and beyond

Method parameters - another rare use case

CompressionStream and DecompressionStream

MengLinMaker commented 4 days ago

Class instantiations solved for issue #45 in PR #47

MengLinMaker commented 4 days ago

Class property access solved for issue #46 in PR #48