-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Santosh Sutar
committed
Aug 25, 2018
1 parent
11d6a57
commit dc9df39
Showing
9 changed files
with
470 additions
and
307 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
const { | ||
get, | ||
getPropName, | ||
getPropType, | ||
getPropCalleeName, | ||
isClassDecoratorProp, | ||
METHOD_DECORATORS | ||
} = require("./util"); | ||
|
||
/** | ||
* Ember Objet Property | ||
* | ||
* A wrapper object for ember object properties | ||
*/ | ||
class EOProp { | ||
constructor(eoProp) { | ||
this._prop = eoProp; | ||
this.decoratorNames = []; | ||
} | ||
|
||
get value() { | ||
return get(this._prop, "value"); | ||
} | ||
|
||
get kind() { | ||
let kind = get(this._prop, "kind"); | ||
if (kind === "init" && this.hasDecorators && !this.hasMethodDecorator) { | ||
kind = "get"; | ||
} | ||
return kind; | ||
} | ||
|
||
get key() { | ||
return get(this._prop, "key"); | ||
} | ||
|
||
get name() { | ||
return getPropName(this._prop); | ||
} | ||
|
||
get type() { | ||
return getPropType(this._prop); | ||
} | ||
|
||
get calleeName() { | ||
return getPropCalleeName(this._prop); | ||
} | ||
|
||
get comments() { | ||
return this._prop.comments; | ||
} | ||
|
||
get computed() { | ||
return this._prop.computed; | ||
} | ||
|
||
get isClassDecorator() { | ||
return isClassDecoratorProp(this.name); | ||
} | ||
|
||
get isCallExpression() { | ||
return this.type === "CallExpression"; | ||
} | ||
|
||
get hasDecorators() { | ||
return this.decoratorNames.length; | ||
} | ||
|
||
get callExprArgs() { | ||
return get(this._prop, "value.arguments") || []; | ||
} | ||
|
||
get hasNonLiteralArg() { | ||
return this.callExprArgs.some(arg => arg.type !== "Literal"); | ||
} | ||
|
||
get hasMethodDecorator() { | ||
return this.decoratorNames.some(decoratormName => | ||
METHOD_DECORATORS.includes(decoratormName) | ||
); | ||
} | ||
|
||
setDecorators(importedDecoratedProps) { | ||
if (this.isCallExpression) { | ||
const decoratorName = importedDecoratedProps[this.calleeName]; | ||
if (decoratorName) { | ||
this.decoratorNames.push(decoratorName); | ||
} | ||
} | ||
} | ||
|
||
addBindingProps(attributeBindingsProps, classNameBindingsProps) { | ||
if (attributeBindingsProps[this.name]) { | ||
this.decoratorNames.push("attribute"); | ||
this.propList = attributeBindingsProps[this.name]; | ||
} else if (classNameBindingsProps[this.name]) { | ||
this.decoratorNames.push("className"); | ||
this.propList = classNameBindingsProps[this.name]; | ||
} | ||
} | ||
} | ||
|
||
module.exports = EOProp; |
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
Oops, something went wrong.