Skip to content

Commit

Permalink
Merge pull request #1081 from benmosher/release
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher authored Apr 15, 2018
2 parents ec87b64 + 2e0ed83 commit 2e41a70
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 29 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Added
- Ignore type imports for named rule ([#931], thanks [@mattijsbliek])
- Add documentation for [`no-useless-path-segments`] rule ([#1068], thanks [@manovotny])


# [2.11.0] - 2018-04-09
### Added
- Fixer for [`first`] ([#1046], thanks [@fengkfengk])
- `allow-require` option for [`no-commonjs`] rule ([#880], thanks [@futpib])

### Fixed
- memory/CPU regression where ASTs were held in memory ([#1058], thanks [@klimashkin]/[@lukeapage])

## [2.10.0] - 2018-03-29
### Added
Expand Down Expand Up @@ -460,6 +469,7 @@ for info on changes for earlier releases.
[#908]: https://github.com/benmosher/eslint-plugin-import/pull/908
[#891]: https://github.com/benmosher/eslint-plugin-import/pull/891
[#889]: https://github.com/benmosher/eslint-plugin-import/pull/889
[#880]: https://github.com/benmosher/eslint-plugin-import/pull/880
[#858]: https://github.com/benmosher/eslint-plugin-import/pull/858
[#843]: https://github.com/benmosher/eslint-plugin-import/pull/843
[#871]: https://github.com/benmosher/eslint-plugin-import/pull/871
Expand Down Expand Up @@ -528,6 +538,7 @@ for info on changes for earlier releases.
[#314]: https://github.com/benmosher/eslint-plugin-import/pull/314
[#912]: https://github.com/benmosher/eslint-plugin-import/pull/912

[#1058]: https://github.com/benmosher/eslint-plugin-import/issues/1058
[#886]: https://github.com/benmosher/eslint-plugin-import/issues/886
[#863]: https://github.com/benmosher/eslint-plugin-import/issues/863
[#842]: https://github.com/benmosher/eslint-plugin-import/issues/842
Expand Down Expand Up @@ -594,7 +605,8 @@ for info on changes for earlier releases.
[#119]: https://github.com/benmosher/eslint-plugin-import/issues/119
[#89]: https://github.com/benmosher/eslint-plugin-import/issues/89

[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.10.0...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v2.11.0...HEAD
[2.11.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.10.0...v2.11.0
[2.10.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.9.0...v2.10.0
[2.9.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.8.0...v2.9.0
[2.8.0]: https://github.com/benmosher/eslint-plugin-import/compare/v2.7.0...v2.8.0
Expand Down Expand Up @@ -698,4 +710,7 @@ for info on changes for earlier releases.
[@graingert]: https://github.com/graingert
[@danny-andrews]: https://github.com/dany-andrews
[@fengkfengk]: https://github.com/fengkfengk
[@futpib]: https://github.com/futpib
[@klimashkin]: https://github.com/klimashkin
[@lukeapage]: https://github.com/lukeapage
[@manovotny]: https://github.com/manovotny
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "2.10.0",
"version": "2.11.0",
"description": "Import with sanity.",
"engines": {
"node": ">=4"
Expand Down
71 changes: 44 additions & 27 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,14 @@ ExportMap.get = function (source, context) {
const path = resolve(source, context)
if (path == null) return null

return ExportMap.for(path, context)
return ExportMap.for(childContext(path, context))
}

ExportMap.for = function (path, context) {
let exportMap
ExportMap.for = function (context) {
const { path } = context

const cacheKey = hashObject({
settings: context.settings,
parserPath: context.parserPath,
parserOptions: context.parserOptions,
path,
}).digest('hex')

exportMap = exportCache.get(cacheKey)
const cacheKey = hashObject(context).digest('hex')
let exportMap = exportCache.get(cacheKey)

// return cached ignore
if (exportMap === null) return null
Expand Down Expand Up @@ -307,6 +301,7 @@ ExportMap.for = function (path, context) {
return null
}

log('cache miss', cacheKey, 'for path', path)
exportMap = ExportMap.parse(path, content, context)

// ambiguous modules return null
Expand Down Expand Up @@ -355,14 +350,14 @@ ExportMap.parse = function (path, content, context) {

const namespaces = new Map()

function remotePath(node) {
return resolve.relative(node.source.value, path, context.settings)
function remotePath(value) {
return resolve.relative(value, path, context.settings)
}

function resolveImport(node) {
const rp = remotePath(node)
function resolveImport(value) {
const rp = remotePath(value)
if (rp == null) return null
return ExportMap.for(rp, context)
return ExportMap.for(childContext(rp, context))
}

function getNamespace(identifier) {
Expand All @@ -385,12 +380,20 @@ ExportMap.parse = function (path, content, context) {
function captureDependency(declaration) {
if (declaration.source == null) return null

const p = remotePath(declaration)
if (p == null || m.imports.has(p)) return p

const getter = () => ExportMap.for(p, context)
m.imports.set(p, { getter, source: declaration.source })
return p
const p = remotePath(declaration.source.value)
if (p == null) return null
const existing = m.imports.get(p)
if (existing != null) return existing.getter

const getter = () => ExportMap.for(childContext(p, context))
m.imports.set(p, {
getter,
source: { // capturing actual node reference holds full AST in memory!
value: declaration.source.value,
loc: declaration.source.loc,
},
})
return getter
}


Expand All @@ -406,8 +409,8 @@ ExportMap.parse = function (path, content, context) {
}

if (n.type === 'ExportAllDeclaration') {
const p = captureDependency(n)
if (p) m.dependencies.add(m.imports.get(p).getter)
const getter = captureDependency(n)
if (getter) m.dependencies.add(getter)
return
}

Expand All @@ -416,7 +419,7 @@ ExportMap.parse = function (path, content, context) {
captureDependency(n)
let ns
if (n.specifiers.some(s => s.type === 'ImportNamespaceSpecifier' && (ns = s))) {
namespaces.set(ns.local.name, n)
namespaces.set(ns.local.name, n.source.value)
}
return
}
Expand All @@ -443,6 +446,7 @@ ExportMap.parse = function (path, content, context) {
}
}

const nsource = n.source && n.source.value
n.specifiers.forEach((s) => {
const exportMeta = {}
let local
Expand All @@ -454,7 +458,7 @@ ExportMap.parse = function (path, content, context) {
break
case 'ExportNamespaceSpecifier':
m.namespace.set(s.exported.name, Object.defineProperty(exportMeta, 'namespace', {
get() { return resolveImport(n) },
get() { return resolveImport(nsource) },
}))
return
case 'ExportSpecifier':
Expand All @@ -469,7 +473,7 @@ ExportMap.parse = function (path, content, context) {
}

// todo: JSDoc
m.reexports.set(s.exported.name, { local, getImport: () => resolveImport(n) })
m.reexports.set(s.exported.name, { local, getImport: () => resolveImport(nsource) })
})
}
})
Expand Down Expand Up @@ -505,3 +509,16 @@ export function recursivePatternCapture(pattern, callback) {
break
}
}

/**
* don't hold full context object in memory, just grab what we need.
*/
function childContext(path, context) {
const { settings, parserOptions, parserPath } = context
return {
settings,
parserOptions,
parserPath,
path,
}
}

0 comments on commit 2e41a70

Please sign in to comment.