Skip to content

Commit

Permalink
feat: 🚀add outer kind variable to help parse import or export
Browse files Browse the repository at this point in the history
  • Loading branch information
TyrealHu committed Feb 21, 2023
1 parent 8b94858 commit 65bd2ad
Show file tree
Hide file tree
Showing 5 changed files with 327 additions and 14 deletions.
170 changes: 170 additions & 0 deletions __test__/__snapshot__/export/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,176 @@ const ExportTypeSnapshot = {
}
],
'sourceType': 'module'
},
ExportTypeAsAsWithName: {
'type': 'Program',
'start': 0,
'end': 50,
'loc': {
'start': {
'line': 1,
'column': 0,
'index': 0
},
'end': {
'line': 4,
'column': 1,
'index': 50
}
},
'body': [
{
'type': 'VariableDeclaration',
'start': 0,
'end': 17,
'loc': {
'start': {
'line': 1,
'column': 0,
'index': 0
},
'end': {
'line': 1,
'column': 17,
'index': 17
}
},
'declarations': [
{
'type': 'VariableDeclarator',
'start': 6,
'end': 17,
'loc': {
'start': {
'line': 1,
'column': 6,
'index': 6
},
'end': {
'line': 1,
'column': 17,
'index': 17
}
},
'id': {
'type': 'Identifier',
'start': 6,
'end': 8,
'loc': {
'start': {
'line': 1,
'column': 6,
'index': 6
},
'end': {
'line': 1,
'column': 8,
'index': 8
}
},
'name': 'as'
},
'init': {
'type': 'Literal',
'start': 11,
'end': 17,
'loc': {
'start': {
'line': 1,
'column': 11,
'index': 11
},
'end': {
'line': 1,
'column': 17,
'index': 17
}
},
'value': 'test',
'raw': '\'test\''
}
}
],
'kind': 'const'
},
{
'type': 'ExportNamedDeclaration',
'start': 18,
'end': 50,
'loc': {
'start': {
'line': 2,
'column': 0,
'index': 18
},
'end': {
'line': 4,
'column': 1,
'index': 50
}
},
'exportKind': 'value',
'declaration': null,
'specifiers': [
{
'type': 'ExportSpecifier',
'start': 29,
'end': 48,
'loc': {
'start': {
'line': 3,
'column': 2,
'index': 29
},
'end': {
'line': 3,
'column': 21,
'index': 48
}
},
'local': {
'type': 'Identifier',
'start': 34,
'end': 36,
'loc': {
'start': {
'line': 3,
'column': 7,
'index': 34
},
'end': {
'line': 3,
'column': 9,
'index': 36
}
},
'name': 'as'
},
'exported': {
'type': 'Identifier',
'start': 40,
'end': 48,
'loc': {
'start': {
'line': 3,
'column': 13,
'index': 40
},
'end': {
'line': 3,
'column': 21,
'index': 48
}
},
'name': 'someName'
},
'exportKind': 'type'
}
],
'source': null
}
],
'sourceType': 'module'
}
}

Expand Down
113 changes: 113 additions & 0 deletions __test__/__snapshot__/import/normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,119 @@ const NormalImportSnapshot = {
}
],
'sourceType': 'module'
},
ImportTypeSpecifierWithAsAsSomethings: {
'type': 'Program',
'start': 0,
'end': 50,
'loc': {
'start': {
'line': 1,
'column': 0,
'index': 0
},
'end': {
'line': 1,
'column': 50,
'index': 50
}
},
'body': [
{
'type': 'ImportDeclaration',
'start': 0,
'end': 50,
'loc': {
'start': {
'line': 1,
'column': 0,
'index': 0
},
'end': {
'line': 1,
'column': 50,
'index': 50
}
},
'importKind': 'value',
'specifiers': [
{
'type': 'ImportSpecifier',
'start': 9,
'end': 30,
'loc': {
'start': {
'line': 1,
'column': 9,
'index': 9
},
'end': {
'line': 1,
'column': 30,
'index': 30
}
},
'imported': {
'type': 'Identifier',
'start': 14,
'end': 16,
'loc': {
'start': {
'line': 1,
'column': 14,
'index': 14
},
'end': {
'line': 1,
'column': 16,
'index': 16
}
},
'name': 'as'
},
'local': {
'type': 'Identifier',
'start': 20,
'end': 30,
'loc': {
'start': {
'line': 1,
'column': 20,
'index': 20
},
'end': {
'line': 1,
'column': 30,
'index': 30
}
},
'name': 'somethings'
},
'importKind': 'type'
}
],
'source': {
'type': 'Literal',
'start': 38,
'end': 50,
'loc': {
'start': {
'line': 1,
'column': 38,
'index': 38
},
'end': {
'line': 1,
'column': 50,
'index': 50
}
},
'value': './index.js',
'raw': '\'./index.js\''
}
}
],
'sourceType': 'module'
}
}

Expand Down
11 changes: 11 additions & 0 deletions __test__/export/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ describe('export type', () => {

equalNode(node, ExportTypeSnapshot.ExportTypeTypeWithAsAs)
})

it('export type as as with name', () => {
const node = parseSource(generateSource([
`const as = 'test'`,
`export {`,
` type as as someName`,
`}`
]))

equalNode(node, ExportTypeSnapshot.ExportTypeAsAsWithName)
})
})
8 changes: 8 additions & 0 deletions __test__/import/normal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ describe('normal syntax', () => {

equalNode(node, NormalImportSnapshot.ImportTypeSpecifierWithAsAs)
})

it('import type specifier with as as', function() {
const node = parseSource(generateSource([
`import { type as as somethings } from './index.js'`,
]))

equalNode(node, NormalImportSnapshot.ImportTypeSpecifierWithAsAsSomethings)
})
})
Loading

0 comments on commit 65bd2ad

Please sign in to comment.