-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compiler does not properly format class names for nested namespa…
…ces (#449) * fix: compiler does not properly format class names for nested namespaces * fix: additional errors with nested namespaces * test: add unit tests for namespace sorting in builder
- Loading branch information
1 parent
adc7230
commit a2bee41
Showing
12 changed files
with
116 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/packages/loader/builder/test/sort-by-namespace.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// @flow | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import sortByNamespace from '../utils/sort-by-namespace'; | ||
|
||
describe('module "loader/builder"', () => { | ||
describe('util sortByNamespace()', () => { | ||
it('returns -1 if "root" is the first argument', () => { | ||
//$FlowIgnore | ||
const result = sortByNamespace(['root'], ['api']); | ||
|
||
expect(result).to.equal(-1); | ||
}); | ||
|
||
it('returns 1 if "root" is the second argument', () => { | ||
//$FlowIgnore | ||
const result = sortByNamespace(['api'], ['root']); | ||
|
||
expect(result).to.equal(1); | ||
}); | ||
|
||
it('returns -1 if the first argument is shorter than the second', () => { | ||
//$FlowIgnore | ||
const result = sortByNamespace(['api'], ['admin']); | ||
|
||
expect(result).to.equal(-1); | ||
}); | ||
|
||
it('returns 1 if the first argument is longer than the second', () => { | ||
//$FlowIgnore | ||
const result = sortByNamespace(['admin'], ['api']); | ||
|
||
expect(result).to.equal(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @flow | ||
import type { Bundle$Namespace } from '../../index'; | ||
|
||
/** | ||
* @private | ||
*/ | ||
export default function sortByNamespace<T>( | ||
[a]: [string, Bundle$Namespace<T>], | ||
[b]: [string, Bundle$Namespace<T>] | ||
): number { | ||
if (a === 'root') { | ||
return -1; | ||
} else if (b === 'root') { | ||
return 1; | ||
} | ||
|
||
return Math.min(Math.max(a.length - b.length, -1), 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
// @flow | ||
export const ID_PATTERN = /(?!=)(\d+)/; | ||
export const DYNAMIC_PATTERN = /(:\w+)/g; | ||
export const RESOURCE_PATTERN = /^((?!\/)[a-z\-]+)/ig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @flow | ||
import type Controller from '../../controller'; | ||
|
||
/** | ||
* @private | ||
*/ | ||
export default function createReplacer( | ||
controllers: Map<string, Controller> | ||
): RegExp { | ||
const names = Array | ||
.from(controllers) | ||
.map(([, { model }]) => model) | ||
.filter(Boolean) | ||
.map(({ resourceName }) => resourceName) | ||
.filter((str, idx, arr) => idx === arr.lastIndexOf(str)) | ||
.join('|'); | ||
|
||
return new RegExp(`(${names})/(\\d+)`, 'ig'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters