-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15968 from emberjs/named-args
Implement named args RFC
- Loading branch information
Showing
9 changed files
with
262 additions
and
38 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
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
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
22 changes: 14 additions & 8 deletions
22
packages/ember-template-compiler/lib/plugins/assert-reserved-named-arguments.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 |
---|---|---|
@@ -1,25 +1,31 @@ | ||
import { assert } from 'ember-debug'; | ||
import { EMBER_GLIMMER_NAMED_ARGUMENTS } from 'ember/features'; | ||
import calculateLocationDisplay from '../system/calculate-location-display'; | ||
|
||
const RESERVED = ['@arguments', '@args']; | ||
|
||
let isReserved, assertMessage; | ||
|
||
export default function assertReservedNamedArguments(env) { | ||
let { moduleName } = env.meta; | ||
|
||
return { | ||
name: 'assert-reserved-named-arguments', | ||
|
||
visitors: { | ||
PathExpression(node) { | ||
if (node.original[0] === '@') { | ||
assert(assertMessage(moduleName, node)); | ||
PathExpression({ original, loc }) { | ||
if (isReserved(original)) { | ||
assert(`${assertMessage(original)} ${calculateLocationDisplay(moduleName, loc)}`); | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
function assertMessage(moduleName, node) { | ||
let path = node.original; | ||
let source = calculateLocationDisplay(moduleName, node.loc); | ||
|
||
return `'${path}' is not a valid path. ${source}`; | ||
if (EMBER_GLIMMER_NAMED_ARGUMENTS) { | ||
isReserved = name => RESERVED.indexOf(name) !== -1 || name.match(/^@[^a-z]/); | ||
assertMessage = name => `'${name}' is reserved.`; | ||
} else { | ||
isReserved = name => name[0] === '@'; | ||
assertMessage = name => `'${name}' is not a valid path.`; | ||
} |
Oops, something went wrong.