Skip to content

Commit 93de410

Browse files
committed
feat: 🚀support ts parse default import
1 parent 7078952 commit 93de410

15 files changed

+732
-0
lines changed

Diff for: ‎.gitignore

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
# ide
12+
13+
.idea/
14+
15+
# Runtime data
16+
pids
17+
*.pid
18+
*.seed
19+
*.pid.lock
20+
21+
# Directory for instrumented libs generated by jscoverage/JSCover
22+
lib-cov
23+
24+
# Coverage directory used by tools like istanbul
25+
coverage
26+
*.lcov
27+
28+
# nyc test coverage
29+
.nyc_output
30+
31+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32+
.grunt
33+
34+
# Bower dependency directory (https://bower.io/)
35+
bower_components
36+
37+
# node-waf configuration
38+
.lock-wscript
39+
40+
# Compiled binary addons (https://nodejs.org/api/addons.html)
41+
build/Release
42+
43+
# Dependency directories
44+
node_modules/
45+
jspm_packages/
46+
47+
# TypeScript v1 declaration files
48+
typings/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Microbundle cache
60+
.rpt2_cache/
61+
.rts2_cache_cjs/
62+
.rts2_cache_es/
63+
.rts2_cache_umd/
64+
65+
# Optional REPL history
66+
.node_repl_history
67+
68+
# Output of 'npm pack'
69+
*.tgz
70+
71+
# Yarn Integrity file
72+
.yarn-integrity
73+
74+
# dotenv environment variables file
75+
.env
76+
.env.test
77+
78+
# parcel-bundler cache (https://parceljs.org/)
79+
.cache
80+
81+
# Next.js build output
82+
.next
83+
84+
# Nuxt.js build / generate output
85+
.nuxt
86+
dist
87+
88+
# Gatsby files
89+
.cache/
90+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
91+
# https://nextjs.org/blog/next-9-1#public-directory-support
92+
# public
93+
94+
# vuepress build output
95+
.vuepress/dist
96+
97+
# Serverless directories
98+
.serverless/
99+
100+
# FuseBox cache
101+
.fusebox/
102+
103+
# DynamoDB Local files
104+
.dynamodb/
105+
106+
# TernJS port file
107+
.tern-port
108+
109+
lib
110+
111+

Diff for: ‎.idea/.gitignore

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎.idea/acorn-typescript.iml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎.idea/thriftCompiler.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry = https://registry.npmjs.org/

Diff for: ‎package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "acorn-typescript",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "ts-node start.ts",
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/TyrealHu/acorn-typescript.git"
13+
},
14+
"author": "tyrealhu",
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/TyrealHu/acorn-typescript/issues"
18+
},
19+
"homepage": "https://github.com/TyrealHu/acorn-typescript#readme",
20+
"devDependencies": {
21+
"@types/estree": "^1.0.0",
22+
"ts-node": "^10.9.1",
23+
"typescript": "^4.8.4"
24+
},
25+
"dependencies": {
26+
"acorn": "^8.8.0"
27+
}
28+
}

Diff for: ‎src/error.ts

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
export const TypeScriptError = {
2+
AbstractMethodHasImplementation: ({ methodName }) =>
3+
`Method '${methodName}' cannot have an implementation because it is marked abstract.`,
4+
AbstractPropertyHasInitializer: ({
5+
propertyName
6+
}) =>
7+
`Property '${propertyName}' cannot have an initializer because it is marked abstract.`,
8+
AccesorCannotDeclareThisParameter:
9+
'\'get\' and \'set\' accessors cannot declare \'this\' parameters.',
10+
AccesorCannotHaveTypeParameters: 'An accessor cannot have type parameters.',
11+
CannotFindName: ({ name }) => `Cannot find name '${name}'.`,
12+
ClassMethodHasDeclare: 'Class methods cannot have the \'declare\' modifier.',
13+
ClassMethodHasReadonly: 'Class methods cannot have the \'readonly\' modifier.',
14+
ConstInitiailizerMustBeStringOrNumericLiteralOrLiteralEnumReference:
15+
'A \'const\' initializer in an ambient context must be a string or numeric literal or literal enum reference.',
16+
ConstructorHasTypeParameters:
17+
'Type parameters cannot appear on a constructor declaration.',
18+
DeclareAccessor: ({ kind }) =>
19+
`'declare' is not allowed in ${kind}ters.`,
20+
DeclareClassFieldHasInitializer:
21+
'Initializers are not allowed in ambient contexts.',
22+
DeclareFunctionHasImplementation:
23+
'An implementation cannot be declared in ambient contexts.',
24+
DuplicateAccessibilityModifier:
25+
// `Accessibility modifier already seen: ${modifier}` would be more helpful.
26+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
27+
() =>
28+
`Accessibility modifier already seen.`,
29+
DuplicateModifier: ({ modifier }) =>
30+
`Duplicate modifier: '${modifier}'.`,
31+
// `token` matches the terminology used by typescript:
32+
// https://github.com/microsoft/TypeScript/blob/main/src/compiler/types.ts#L2915
33+
EmptyHeritageClauseType: ({ token }) =>
34+
`'${token}' list cannot be empty.`,
35+
EmptyTypeArguments: 'Type argument list cannot be empty.',
36+
EmptyTypeParameters: 'Type parameter list cannot be empty.',
37+
ExpectedAmbientAfterExportDeclare:
38+
'\'export declare\' must be followed by an ambient declaration.',
39+
ImportAliasHasImportType: 'An import alias can not use \'import type\'.',
40+
IncompatibleModifiers: ({
41+
modifiers
42+
43+
}) =>
44+
`'${modifiers[0]}' modifier cannot be used with '${modifiers[1]}' modifier.`,
45+
IndexSignatureHasAbstract:
46+
'Index signatures cannot have the \'abstract\' modifier.',
47+
IndexSignatureHasAccessibility: ({
48+
modifier
49+
}) =>
50+
`Index signatures cannot have an accessibility modifier ('${modifier}').`,
51+
IndexSignatureHasDeclare:
52+
'Index signatures cannot have the \'declare\' modifier.',
53+
IndexSignatureHasOverride:
54+
'\'override\' modifier cannot appear on an index signature.',
55+
IndexSignatureHasStatic:
56+
'Index signatures cannot have the \'static\' modifier.',
57+
InitializerNotAllowedInAmbientContext:
58+
'Initializers are not allowed in ambient contexts.',
59+
InvalidModifierOnTypeMember: ({ modifier }) =>
60+
`'${modifier}' modifier cannot appear on a type member.`,
61+
InvalidModifierOnTypeParameter: ({ modifier }) =>
62+
`'${modifier}' modifier cannot appear on a type parameter.`,
63+
InvalidModifierOnTypeParameterPositions: ({
64+
modifier
65+
}) =>
66+
`'${modifier}' modifier can only appear on a type parameter of a class, interface or type alias.`,
67+
InvalidModifiersOrder: ({
68+
orderedModifiers
69+
}) =>
70+
`'${orderedModifiers[0]}' modifier must precede '${orderedModifiers[1]}' modifier.`,
71+
InvalidPropertyAccessAfterInstantiationExpression:
72+
'Invalid property access after an instantiation expression. ' +
73+
'You can either wrap the instantiation expression in parentheses, or delete the type arguments.',
74+
InvalidTupleMemberLabel:
75+
'Tuple members must be labeled with a simple identifier.',
76+
MissingInterfaceName:
77+
'\'interface\' declarations must be followed by an identifier.',
78+
MixedLabeledAndUnlabeledElements:
79+
'Tuple members must all have names or all not have names.',
80+
NonAbstractClassHasAbstractMethod:
81+
'Abstract methods can only appear within an abstract class.',
82+
NonClassMethodPropertyHasAbstractModifer:
83+
'\'abstract\' modifier can only appear on a class, method, or property declaration.',
84+
OptionalTypeBeforeRequired:
85+
'A required element cannot follow an optional element.',
86+
OverrideNotInSubClass:
87+
'This member cannot have an \'override\' modifier because its containing class does not extend another class.',
88+
PatternIsOptional:
89+
'A binding pattern parameter cannot be optional in an implementation signature.',
90+
PrivateElementHasAbstract:
91+
'Private elements cannot have the \'abstract\' modifier.',
92+
PrivateElementHasAccessibility: ({
93+
modifier
94+
}) =>
95+
`Private elements cannot have an accessibility modifier ('${modifier}').`,
96+
ReadonlyForMethodSignature:
97+
'\'readonly\' modifier can only appear on a property declaration or index signature.',
98+
ReservedArrowTypeParam:
99+
'This syntax is reserved in files with the .mts or .cts extension. Add a trailing comma, as in `<T,>() => ...`.',
100+
ReservedTypeAssertion:
101+
'This syntax is reserved in files with the .mts or .cts extension. Use an `as` expression instead.',
102+
SetAccesorCannotHaveOptionalParameter:
103+
'A \'set\' accessor cannot have an optional parameter.',
104+
SetAccesorCannotHaveRestParameter:
105+
'A \'set\' accessor cannot have rest parameter.',
106+
SetAccesorCannotHaveReturnType:
107+
'A \'set\' accessor cannot have a return type annotation.',
108+
SingleTypeParameterWithoutTrailingComma: ({ typeParameterName }) =>
109+
`Single type parameter ${typeParameterName} should have a trailing comma. Example usage: <${typeParameterName},>.`,
110+
StaticBlockCannotHaveModifier:
111+
'Static class blocks cannot have any modifier.',
112+
TypeAnnotationAfterAssign:
113+
'Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.',
114+
TypeImportCannotSpecifyDefaultAndNamed:
115+
'A type-only import can specify a default import or named bindings, but not both.',
116+
TypeModifierIsUsedInTypeExports:
117+
'The \'type\' modifier cannot be used on a named export when \'export type\' is used on its export statement.',
118+
TypeModifierIsUsedInTypeImports:
119+
'The \'type\' modifier cannot be used on a named import when \'import type\' is used on its import statement.',
120+
UnexpectedParameterModifier:
121+
'A parameter property is only allowed in a constructor implementation.',
122+
UnexpectedReadonly:
123+
'\'readonly\' type modifier is only permitted on array and tuple literal types.',
124+
UnexpectedTypeAnnotation: 'Did not expect a type annotation here.',
125+
UnexpectedTypeCastInParameter: 'Unexpected type cast in parameter position.',
126+
UnsupportedImportTypeArgument:
127+
'Argument in a type import must be a string literal.',
128+
UnsupportedParameterPropertyKind:
129+
'A parameter property may not be declared using a binding pattern.',
130+
UnsupportedSignatureParameterKind: ({ type }) =>
131+
`Name in a signature must be an Identifier, ObjectPattern or ArrayPattern, instead got ${type}.`
132+
}

0 commit comments

Comments
 (0)