Skip to content

Commit

Permalink
fix overwriting of dynamic import callexpression
Browse files Browse the repository at this point in the history
  • Loading branch information
vikr01 committed Oct 21, 2018
1 parent b4a2f11 commit 19f7442
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/src/rules/no-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ ruleTester.run('no-cycle', rule, {
code: 'import { foo } from "./depth-two"',
options: [{ maxDepth: 1 }],
}),
test({
code: 'import("./depth-two").then(function({ foo }){})',
options: [{ maxDepth: 1 }],
parser: 'babel-eslint',
}),
test({
code: 'import type { FooType } from "./depth-one"',
parser: 'babel-eslint',
Expand Down Expand Up @@ -88,6 +93,16 @@ ruleTester.run('no-cycle', rule, {
code: 'import { bar } from "./depth-three-indirect"',
errors: [error(`Dependency cycle via ./depth-two:1=>./depth-one:1`)],
}),
// test({
// code: 'import("./depth-three-star")',
// errors: [error(`Dependency cycle via ./depth-two:1=>./depth-one:1`)],
// parser: 'babel-eslint',
// }),
// test({
// code: 'import("./depth-three-indirect")',
// errors: [error(`Dependency cycle via ./depth-two:1=>./depth-one:1`)],
// parser: 'babel-eslint',
// }),
],
})
// })
8 changes: 8 additions & 0 deletions tests/src/rules/no-relative-parent-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ ruleTester.run('no-relative-parent-imports', rule, {
line: 1,
column: 17
}]
}),
test({
code: 'import("../../api/service")',
errors: [ {
message: 'Relative imports from parent directories are not allowed. Please either pass what you\'re importing through at runtime (dependency injection), move `index.js` to same directory as `../../api/service` or consider making `../../api/service` a package.',
line: 1,
column: 8
}],
})
],
})
9 changes: 9 additions & 0 deletions tests/src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function runResolverTests(resolver) {
rest({ code: "import bar from './bar.js';" }),
rest({ code: "import {someThing} from './test-module';" }),
rest({ code: "import fs from 'fs';" }),
rest({ code: "import('fs');"
, parser: 'babel-eslint' }),

rest({ code: 'import * as foo from "a"' }),

Expand Down Expand Up @@ -114,6 +116,13 @@ function runResolverTests(resolver) {
"module 'in-alternate-root'."
, type: 'Literal',
}]}),
rest({
code: "import('in-alternate-root').then(function({DEEP}){});",
errors: [{ message: 'Unable to resolve path to ' +
"module 'in-alternate-root'."
, type: 'Literal',
}],
parser: 'babel-eslint'}),

rest({ code: 'export { foo } from "./does-not-exist"'
, errors: ["Unable to resolve path to module './does-not-exist'."] }),
Expand Down
21 changes: 21 additions & 0 deletions tests/src/rules/no-useless-path-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ function runResolverTests(resolver) {
test({ code: 'import "."' }),
test({ code: 'import ".."' }),
test({ code: 'import fs from "fs"' }),
test({ code: 'import(".")'
, parser: 'babel-eslint' }),
test({ code: 'import("..")'
, parser: 'babel-eslint' }),
test({ code: 'import("fs").then(function(fs){})'
, parser: 'babel-eslint' }),
],

invalid: [
Expand Down Expand Up @@ -95,6 +101,21 @@ function runResolverTests(resolver) {
code: 'import "./deep//a"',
errors: [ 'Useless path segments for "./deep//a", should be "./deep/a"'],
}),
test({
code: 'import("./")',
errors: [ 'Useless path segments for "./", should be "."'],
parser: 'babel-eslint',
}),
test({
code: 'import("../")',
errors: [ 'Useless path segments for "../", should be ".."'],
parser: 'babel-eslint',
}),
test({
code: 'import("./deep//a")',
errors: [ 'Useless path segments for "./deep//a", should be "./deep/a"'],
parser: 'babel-eslint',
}),
],
})
}
Expand Down
3 changes: 3 additions & 0 deletions utils/moduleVisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ exports.default = function visitModules(visitor, options) {
}

if (options.commonjs || options.amd) {
const currentCallExpression = visitors['CallExpression']
visitors['CallExpression'] = function (call) {
if (currentCallExpression) currentCallExpression(call)
if (options.commonjs) checkCommon(call)
if (options.amd) checkAMD(call)
}
}


return visitors
}

Expand Down

0 comments on commit 19f7442

Please sign in to comment.