Skip to content

Commit

Permalink
Add back trailing- and leadingComments properties to typescript nodes
Browse files Browse the repository at this point in the history
Also updates the tree view to indicate computed properties with `*`.
  • Loading branch information
fkling committed Dec 12, 2015
1 parent 5c21f8d commit f933252
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/components/ast/Element.js
Expand Up @@ -25,6 +25,7 @@ export default class Element extends React.Component {
static propTypes = {
name: PropTypes.string,
value: PropTypes.any.isRequired,
computed: PropTypes.bool,
deepOpen: PropTypes.bool,
focusPath: PropTypes.array.isRequired,
level: PropTypes.number,
Expand All @@ -42,7 +43,7 @@ export default class Element extends React.Component {
this._onMouseLeave = this._onMouseLeave.bind(this);
this._onMouseOver = this._onMouseOver.bind(this);
this._toggleClick = this._toggleClick.bind(this);
const {value, name, deepOpen, parser, focusPath, settings} = props;
const {value, name, deepOpen, parser} = props;
// Some elements should be open by default
let open =
props.open ||
Expand Down Expand Up @@ -143,14 +144,15 @@ export default class Element extends React.Component {
this.setState(state);
}

_createSubElement(key, value, name) {
_createSubElement(key, value, name, computed) {
return (
<Element
key={key}
name={name}
focusPath={this.props.focusPath}
deepOpen={this.state.deepOpen}
value={value}
computed={computed}
level={this.props.level + 1}
parser={this.props.parser}
settings={this.props.settings}
Expand All @@ -164,7 +166,6 @@ export default class Element extends React.Component {
focusPath,
parser,
level,
settings,
} = this.props;
const {
open,
Expand Down Expand Up @@ -198,7 +199,12 @@ export default class Element extends React.Component {
suffix = ']';
let elements = this._getProperties(parser, value)
.filter(({key}) => key !== 'length')
.map(({key, value}) => this._createSubElement(key, value, Number.isInteger(+key) ? undefined : key));
.map(({key, value, computed}) => this._createSubElement(
key,
value,
Number.isInteger(+key) ? undefined : key,
computed,
));
content = <ul className="value-body">{elements}</ul>;
} else {
valueOutput =
Expand All @@ -216,7 +222,12 @@ export default class Element extends React.Component {
prefix = '{';
suffix = '}';
let elements = this._getProperties(parser, value)
.map(({key, value}) => this._createSubElement(key, value, key));
.map(({key, value, computed}) => this._createSubElement(
key,
value,
key,
computed
));
content = <ul className="value-body">{elements}</ul>;
showToggler = elements.length > 0;
} else {
Expand Down Expand Up @@ -249,7 +260,12 @@ export default class Element extends React.Component {
null
)
}>
<span className="name nb">{this.props.name}</span>
<span className="name nb">
{this.props.computed ?
<span title="computed">*{this.props.name}</span> :
this.props.name
}
</span>
<span className="p">: </span>
</span> :
null;
Expand Down
10 changes: 10 additions & 0 deletions src/parsers/js/typescript.js
Expand Up @@ -113,6 +113,16 @@ export default {
key: prop,
};
}
yield {
value: getComments(node),

This comment has been minimized.

Copy link
@RReverser

RReverser Dec 12, 2015

Collaborator

I was confused by this when modifying - getComments doesn't seem to return collected comments, it just patches the nodes, how does this work then?

This comment has been minimized.

Copy link
@fkling

fkling Dec 12, 2015

Author Owner

At some point the whole tree was traversed and getComments was called on every node. But this was removed during the refactoring and we forgot to call getComments again. Not sure if we should even add it...

But you are right, this only works by accident. Will fix it so that it returns the comments.

This comment has been minimized.

Copy link
@RReverser

RReverser Dec 12, 2015

Collaborator

this only works by accident

The problem is that it doesn't work (at least for me) even now, just shows leadingComments: undefined & trailingComments: undefined.

This comment has been minimized.

Copy link
@RReverser

RReverser Dec 12, 2015

Collaborator

Ohh... It actually works only where they were previously added by patching, not because of this re-added yield but because of regular loop cycle (and thus not marked with *).
2015-12-12_20-55-30

This comment has been minimized.

Copy link
@fkling

fkling Dec 12, 2015

Author Owner

Well, there is only a single node that has leading comments:

screen shot 2015-12-12 at 12 56 43 pm

This comment has been minimized.

Copy link
@RReverser

RReverser Dec 12, 2015

Collaborator

Yes, but as you can see, it's not yield which output them (it doesn't have * mark of computed property).

This comment has been minimized.

Copy link
@fkling

fkling Dec 12, 2015

Author Owner

Yeah, that's why "accidentally" ;)

key: 'leadingComments',
computed: true,
};
yield {
value: getComments(node, true),
key: 'trailingCommments',
computed: true,
};
},

nodeToRange(node) {
Expand Down

0 comments on commit f933252

Please sign in to comment.