-
Notifications
You must be signed in to change notification settings - Fork 575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate from angular selectors. ENG-7482 #1653
Changes from 5 commits
6888b88
1ce09e3
a54c48d
9ada8a4
d7dee37
bd3c03a
2314e23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { parse } from '../generators/angular/parse-selector'; | ||
|
||
describe('Angular selectors', () => { | ||
test('should parse gnarly selectors', () => { | ||
expect(parse('ccc.c1#wat[co].c2[counter="cool"]#wat[x=\'y\'].c3')).toEqual({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are support for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I should add parsing for those. They don't affect the code generation but will need to be accounted for in the parsing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok great! Only other thing I can think of here is to add a test for those cases for parsing. |
||
element: 'ccc', | ||
classNames: ['c1', 'c2', 'c3'], | ||
attributes: { | ||
co: '', | ||
counter: 'cool', | ||
id: 'wat', | ||
x: 'y', | ||
}, | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { CssSelector } from '@angular/compiler'; | ||
|
||
export function parse(selector: string) { | ||
const { element, classNames, attrs } = CssSelector.parse(selector)[0]; | ||
const attributes = attrs.reduce((acc, attr, i) => { | ||
if (i % 2 === 0) { | ||
acc[attr] = attrs[i + 1]; | ||
} | ||
return acc; | ||
}, {} as Record<string, string>); | ||
|
||
return { | ||
element, | ||
classNames, | ||
attributes, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh one more thing I just noticed: Do you intend for this to be a version bump in Mitosis? If so, you'll need to generate a new changeset.