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

Nested component tags of same type throws an error #780

Merged
merged 4 commits into from Mar 12, 2014

Conversation

Projects
None yet
2 participants
@ccummings
Contributor

ccummings commented Mar 12, 2014

If component tags of the same type are immediately nested and have inner content, the Scanner generates a compiled template which throws an error when it is eval'd. Simplest case is two immediately nested tags, but the same happens with more than 2.

The problem is in the scanner where we do custom tag hookups. Normally, the tag in the top of the hookup stack (top(specialStates.tagHookups)) is different than the current tagName so we hit the else condition which will generate the code to close out the hookup, but in the case where we have two tags the same, tagName is the same and we try to hookup the tag again.

For this template:

<my-tag><my-tag>In</my-tag></my-tag>

The Scanner generates:

this.fn = (function (scope, options) {
    var ___v1ew = [];
    ___v1ew.push(
        "<my-tag", can.view.Scanner.hookupTag({
            tagName: 'my-tag',
            scope: scope,
            options: options,
            subtemplate: function (scope, options) {
                var ___v1ew = [];
                ___v1ew.push(
                    "<my-tag", can.view.Scanner.hookupTag({
                        tagName: 'my-tag',
                        scope: scope,
                        options: options,
                        subtemplate: function (scope, options) {
                            var ___v1ew = [];
                            ___v1ew.push(
                                "In");
                            return ___v1ew.join('')
                        }
                    }));
                   //we should be closing out the hookup here instead of generating code for another one
                    ___v1ew.push(
                        "></my-tag", can.view.Scanner.hookupTag({
                            tagName: 'my-tag',
                            scope: scope,
                            options: options
                        }));
                    ___v1ew.push(
                        "></my-tag>\n\t");;
                    return ___v1ew.join('')
                });

The first two can.view.Scanner.hookupTag blocks are fine, the third one is wrong. Instead this code should look like this:

this.fn = (function (scope, options) {
    var ___v1ew = [];
    ___v1ew.push(
        "<my-tag", can.view.Scanner.hookupTag({
            tagName: 'my-tag',
            scope: scope,
            options: options,
            subtemplate: function (scope, options) {
                var ___v1ew = [];
                ___v1ew.push(
                    "<my-tag", can.view.Scanner.hookupTag({
                        tagName: 'my-tag',
                        scope: scope,
                        options: options,
                        subtemplate: function (scope, options) {
                            var ___v1ew = [];
                            ___v1ew.push(
                                "In");
                            return ___v1ew.join('')
                        }
                    }));
                    //this is what should be generated
                    ___v1ew.push(
                    "></demo>");
                return ___v1ew.join('')
            }
        }));
    ___v1ew.push(
        "></demo>\n\t");;
    return ___v1ew.join('')
});

@ccummings ccummings added this to the 2.0.6 milestone Mar 12, 2014

daffl added a commit that referenced this pull request Mar 12, 2014

Merge pull request #780 from bitovi/nested-component-error
Nested component tags of same type throws an error

@daffl daffl merged commit c140d9f into master Mar 12, 2014

1 check passed

default The Travis CI build passed
Details

@daffl daffl deleted the nested-component-error branch Mar 12, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment