this[type] is not a function
See original GitHub issueI’m need to modify js file. So I parse my JSX with esprima, make some changes and then I’m trying to code AST into js. But I have this error this[type] is not a function
Code
import React from 'react';
import { Route, IndexRoute } from 'react-router';
import { Map } from 'immutable';
import App from './containers/App';
export const pages = new Map({
index: '/'
});
/*eslint-disable react/jsx-max-props-per-line*/
/*eslint-disable react/jsx-sort-props*/
/*eslint-disable max-len*/
export default (
<Route path = { pages.get('index') } component = { App }>
<IndexRoute component = { App } />
</Route>
);
Parsing file:
const file = fs.readFileSync(routes, 'utf8');
const parsedFile = esprima.parse(file, {
sourceType: 'module',
jsx: true,
comment: true
});
let token = false;
for (let i = 0; i < parsedFile.body.length; i++) {
if (parsedFile.body[i].type === 'ExportNamedDeclaration') {
const declarations = parsedFile.body[i].declaration.declarations;
for (let j = 0; j < declarations.length; j++) {
if (declarations[j].id.name === 'pages') {
const properties = declarations[j].init.arguments[0].properties;
properties.push({
type: 'Property',
key: {type: 'Identifier', name: 'test'},
computed: false,
value: {type: 'Literal', value: '/test'},
kind: 'init',
method: false,
shorthand: false
});
}
}
}
token = true;
}
Escoding:
const code = escodegen.generate(parsedFile, {
format: {
indent: {
style: ' ',
base: 0,
adjustMultilineComment: true
},
newline: '\n',
space: ' ',
json: false,
renumber: false,
hexadecimal: false,
quotes: 'single',
escapeless: false,
compact: false,
parentheses: true,
semicolons: true,
safeConcatenation: false
},
moz: {
starlessGenerator: false,
parenthesizedComprehensionBlock: false,
comprehensionExpressionStartsWithAssignment: false
},
parse: null,
comment: true,
sourceMap: undefined,
sourceMapRoot: null,
sourceMapWithCode: false,
file: undefined,
directive: false,
verbatim: undefined
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:22 (9 by maintainers)
Top Results From Across the Web
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >Declaring the type of 'this' in a typescript function?
Now (from TS 2.0) you can specify function's this type by using fake this parameter (should be the first one): grunt.registerMultiTask('clean' ...
Read more >Documentation - Utility Types - TypeScript
This type is meant to model operations like await in async functions, ... type with all the parameter types (or the type never...
Read more >How To Fix Split is Not a Function Error in JavaScript - Isotropic
It is great being able to code quickly and efficiently without having to worry about type safety. Of course, without this type safety,...
Read more >Troubleshooting F# | F# for fun and profit
This type (function type) does not match the type (simple type). Note: function types have a arrow in them, like 'a -> 'b...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any update on this issue? Do you plan to resolve it soon?
Would we be able to sync this bad boy in here? https://github.com/wallabyjs/escodegen