Skip to content

Commit

Permalink
feat(typescript): support import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Goose97 committed Nov 21, 2024
1 parent f1c8caf commit 1cc03ed
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/neolog/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ local M = {}
local LANGUAGE_SPEC = {
typescript = {
identifier = { "identifier", "shorthand_property_identifier_pattern" },
container = { "lexical_declaration", "return_statement", "expression_statement" },
container = { "lexical_declaration", "return_statement", "expression_statement", "import_statement" },
},
tsx = {
identifier = { "identifier", "shorthand_property_identifier_pattern" },
container = { "lexical_declaration", "return_statement", "expression_statement" },
container = { "lexical_declaration", "return_statement", "expression_statement", "import_statement" },
},
}

Expand Down
128 changes: 128 additions & 0 deletions tests/neolog/actions/lang/typescript_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -464,4 +464,132 @@ describe("typescript", function()
})
end)
end)

describe("supports import statements", function()
it("supports plain imports", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
import f|oo from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "below")
end,
expected = [[
import foo from 'bar'
console.log("foo", foo)
]],
})

helper.assert_scenario({
input = [[
import f|oo from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "above")
end,
expected = [[
console.log("foo", foo)
import foo from 'bar'
]],
})
end)

it("supports named imports", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
import { fo|o } from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "below")
end,
expected = [[
import { foo } from 'bar'
console.log("foo", foo)
]],
})

helper.assert_scenario({
input = [[
import { fo|o } from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "above")
end,
expected = [[
console.log("foo", foo)
import { foo } from 'bar'
]],
})
end)

it("supports named alias imports", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
import { foo as b|ar } from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "below")
end,
expected = [[
import { foo as bar } from 'bar'
console.log("bar", bar)
]],
})
helper.assert_scenario({
input = [[
import { foo as b|ar } from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "above")
end,
expected = [[
console.log("bar", bar)
import { foo as bar } from 'bar'
]],
})
end)

it("supports namespace imports", function()
local actions = require("neolog.actions")

helper.assert_scenario({
input = [[
import * as f|oo from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "below")
end,
expected = [[
import * as foo from 'bar'
console.log("foo", foo)
]],
})
helper.assert_scenario({
input = [[
import * as f|oo from 'bar'
]],
filetype = "typescript",
action = function()
actions.add_log("%identifier", "above")
end,
expected = [[
console.log("foo", foo)
import * as foo from 'bar'
]],
})
end)
end)
end)

0 comments on commit 1cc03ed

Please sign in to comment.