Skip to content
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

Develop #27

Draft
wants to merge 62 commits into
base: master
Choose a base branch
from
Draft

Develop #27

wants to merge 62 commits into from

Conversation

CAndRyan
Copy link

[WIP] Add support for helpers, partials, & additional functionality -- DO NOT MERGE

const getAllOpeningTagDataRegex = /<([^>]*)\/?>/g;

// NOTE: this regex will identify all explicit helper calls (i.e. a mustache statement with multiple arguments)
// NOTE: this will not locate helper's that take 0 args since they cannot be distiniguished from basic mustache statements without additional context
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: is there a way to distinguish helpers that take 0 args, perhaps a manual tagging process?

// TODO: fix this hack
// Instead of forcing formatting here, fix whatever is causing certain expressions to print with pre- or post- line breaks
// A quick search through forked-glimmer-vm (aka glimmer-engine) didn't show anything apparent in the generator/printer
export const print = (text: string): string => removeLineBreaks(text);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: identify where extra line breaks are coming from so this formatting hack can be removed

);
const externalImports = externals.map((name) => Babel.importDeclaration(
[Babel.importDefaultSpecifier(Babel.identifier(name))],
Babel.stringLiteral(`./${name}`) // TODO: add support for specifying partial and/or helpers directory
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add support for specifying partial and/or helpers directory

expectedTemplate: '<div title="{{titleIfHelper hasTooltip tooltip}}"></div>',
expectedHelpers: [`const titleIfHelper = (hasTooltip, tooltip) => hasTooltip ? tooltip : undefined;`]
},
// { // TODO: support multiple conditional attributes within the same block?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: support multiple conditional attributes within the same block?

expectedTemplate: `<div ${ATTRIBUTE_GENERATOR_HELPER_FUNCTION}="{{getDataAttributesString data prefix="data-"}}"></div>`,
expectedHelpers: []
},
// { // TODO: support multiple attribute generator helpers within the same opening tag?
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: support multiple attribute generator helpers within the same opening tag?

replaceAttributeGeneratingHelpers, // NOTE: this preprocessor has a dependency on having already converted attributes that contain helpers within or around their value
];

const preProcessUnsupportedParserFeatures = (handlebarsTemplate: string):PreparedTemplate => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: look into proper parser support for these features, to avoid the need for flaky pre-processing

}

const [_, leadingData, originalHelperName, originalHelperArg, helperChild, __, trailingData] = attributeValueData;
if (helperChild.match(containsMustacheBlockRegex)) { // TODO: support helperChild being a block statement (use recursion?)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO: support helperChild being a block statement (use recursion?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant