I have a macro where I take in any code in between parenthesis. I then pass it to another macro that has rules on that code. I do other things in test and it is named differently, but I figured a minimal testcase would be useful here.
macro testimpl {
rule {
{ $lhs:expr is $rhs:expr }
} => {
}
}
macro test {
rule { $code ... } => { testimpl { $code ... } }
}
testimpl { true is true } // Works
test(true is true) // Throws the next error
Here's the error message I get:
{ name: 'macro',
message: 'Macro `testimpl` could not be matched with `{} ...`',
stx:
{ token:
{ type: 3,
value: 'testimpl',
lineNumber: 13,
lineStart: 98,
range: [Object],
sm_lineNumber: 9,
sm_lineStart: 98,
sm_range: [Object],
leadingComments: [Object] },
context: { mark: 649, context: [Object], instNum: 131515 },
deferredContext: null } }
/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:100
throw new SyntaxError(syn.printSyntaxError(source$2, err))
^
SyntaxError: [macro] Macro `testimpl` could not be matched with `{} ...`
9: rule { $code ... } => { testimpl { $code ... } }
^
at expand$2 (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:100:27)
at parse (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:136:29)
at Object.compile (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sweet.js:144:19)
at Object.exports.run (/home/havvy/sweetjs/playground/node_modules/sweet.js/lib/sjs.js:85:27)
at Object.<anonymous> (/home/havvy/sweetjs/playground/node_modules/sweet.js/bin/sjs:7:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
I think you are missing the outer parens in the rule for test.
test(true is true)
expands to
testimpl { (true is true) }
which doesn't match your rule in testimpl.
Changing the test rule to rule { ($code ...) } should work.
Related
I am trying to use the '#ensdomains/eth-ens-namehash' package to hash an input.
I am using it in combination with 'pinia'.
I call on this method in Nuxt3.
This is the code:
import { defineStore } from "pinia"
import namehash from "#ensdomains/eth-ens-namehash"
import { Buffer } from 'buffer'
export const exampleMethod = defineStore('example', {
state: () => {
return{
hash: String
}
},
actions: {
method(input) {
globalThis.Buffer = Buffer
this.hash = namehash.hash(input).toString()
}
}
}
When trying to call 'method' I get the following error:
Uncaught (in promise) Error: Module "punycode" has been externalized
for browser compatibility. Cannot access "punycode.ucs2" in client
code.
I have a vuex-orm model called Profile.js
import { Model } from '#vuex-orm/core'
export default class Profile extends Model {
static entity = 'profile'
static fields () {
return {
id: this.uid(),
// etc...
}
}
}
When I run ionic serve I get the following output:
Build finished at 14:20:05 by 0.000s
[INFO] Browser window opened to http://localhost:4200!
ERROR in
[vue-cli-service] /home/user/IonicProjects/ionic/iloveu/src/store/models/Profile.js
[vue-cli-service] 4:19 error Parsing error: Unexpected token =
[vue-cli-service]
[vue-cli-service] ✖ 1 problem (1 error, 0 warnings)
[vue-cli-service]
[vue-cli-service] webpack compiled with 1 error
So it complains about this line
static entity = 'profile'
which is perfectly valid javascript or ecmascript.
What can I do so this valid code is not being tagged as erroneous?
my .eslintrc
module.exports = {
root: true,
env: {
node: true
},
'extends': [
'plugin:vue/vue3-essential',
'prettier'
],
parserOptions: {
ecmaVersion: 2020
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'vue/no-deprecated-slot-attribute': 'off'
},
overrides: [
{
files: [
'**/__tests__/*.{j,t}s?(x)',
'**/tests/unit/**/*.spec.{j,t}s?(x)'
],
env: {
jest: true
}
}
]
}
reference to the vuex-orm documentation
Seems like this is the culprint
parserOptions: {
ecmaVersion: 2020
},
changing it to
parserOptions: {
ecmaVersion: 2022
},
does not return this error anymore, which is weird because the Quasar framework uses ecmaVersion: 2018 and does not have this error.
I try to use mockServer of graphql-tools to mock an Mutation.
here is my unit test:
it('should update user name correctly', () => {
mockserver
.query(
`{
Mutation {
updateUserName(id: 1, name: "du") {
id
name
}
}
}`
)
.then(res => {
console.log(res);
expect(1).to.be.equal(1);
});
});
But, got an error:
mock server test suites
✓ should get users correctly
✓ should get user by id correctly
✓ should update user name correctly
{ errors:
[ { GraphQLError: Cannot query field "Mutation" on type "Query".
at Object.Field (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/validation/rules/FieldsOnCorrectType.js:65:31)
at Object.enter (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/language/visitor.js:324:29)
at Object.enter (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/language/visitor.js:366:25)
at visit (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/language/visitor.js:254:26)
at visitUsingRules (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/validation/validate.js:74:22)
at validate (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/validation/validate.js:59:10)
at graphqlImpl (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/graphql.js:106:50)
at /Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/graphql.js:66:223
at new Promise (<anonymous>)
at Object.graphql (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql/graphql.js:63:10)
at Object.query (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/graphql-tools/dist/mock.js:19:63)
at Context.it (/Users/ldu020/workspace/apollo-server-express-starter/src/mockServer/index.spec.js:95:8)
at callFn (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runnable.js:383:21)
at Test.Runnable.run (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runnable.js:375:7)
at Runner.runTest (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runner.js:446:10)
at /Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runner.js:564:12
at next (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runner.js:360:14)
at /Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runner.js:370:7
at next (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runner.js:294:14)
at Immediate.<anonymous> (/Users/ldu020/workspace/apollo-server-express-starter/node_modules/mocha/lib/runner.js:338:5)
at runCallback (timers.js:763:18)
at tryOnImmediate (timers.js:734:5)
at processImmediate (timers.js:716:5)
message: 'Cannot query field "Mutation" on type "Query".',
locations: [Array],
path: undefined } ] }
and, I read graphql-tools interface.d.ts file.
export interface IMockServer {
query: (query: string, vars?: {
[key: string]: any;
}) => Promise<ExecutionResult>;
}
Obviously, there is no mutation function in mockServer.
Does mockServer support Mutation?
https://github.com/apollographql/graphql-tools/issues/279
It's the structure of your query. The query should be structured much like you would in GraphiQL such as:
mutation {
updateUserName(id: 1, name: "du") {
id
name
}
}
Hence, your code should look something like this, with the mutation keyword as the first thing in your query before your opening brace { :
it('should update user name correctly', () => {
mockserver
.query(`mutation {
updateUserName(id: 1, name: "du") {
id
name
}
}`)
.then(res => {
console.log(res);
expect(1).to.be.equal(1);
});
});
I'm getting the error
Invalid exit definition ("success"). Must be a dictionary-- i.e. plain JavaScript object like `{}`.
Invalid exit definition ("error"). Must be a dictionary-- i.e. plain JavaScript object like `{}`.
when doing sails lift. The error is on getRole.js
module.exports = {
friendlyName: 'Get Role',
description: '',
inputs: {
user_id: {
friendlyName: 'User Id',
description: 'The ID of the user to check role',
type: 'string',
required: true
}
},
exits: {
success: function (role){
return role;
},
error: function (message) {
return message;
}
},
fn: function (inputs, exits) {
User.findOne({ id: inputs.user_id } , function (err, user) {
if (err) return exits.err(err);
return exits.success(user.role);
});
}
};
This is a new error, and looking at my git, nothing has changed in my code since it successfully compiled. I understand the Sails version (v1.0) I'm using in beta, so I'm taking that into account.
Exits cannot be defined as functions. There is a special syntax (Machine Spec) to define exits. In your example this should work:
exits: {
error: {
description: 'Unexpected error occurred.',
},
success: {
description: 'Role was succesffuly fetched'
}
},
You can read more info about helper exits here: https://next.sailsjs.com/documentation/concepts/helpers
May changes occur on the last release 1.0.0-38. I've not checked underneath yet, but the way to execute helpers changed: on .exec() I get errors. Now, use .switch();
I have an existing tree which builds off of JSON with 3 level hierarchy.
Root ->
ChildLevel1 ->
ChildLevel2 (lazy =true)
The above tree data is loaded as the source on pageload., everything works fine at this point.Now - on childlevel2 I am trying to fill children on the fly as such :
lazyLoad: function (event, data) {
var json = "{children:[ {\"title\": \"Sub item\", \"lazy\": true }, {\"title\": \"Sub folder\", \"folder\": true, \"lazy\": true } ]}";
data.result = json;
}
I keep getting the following exception :
Uncaught Error: Fancytree assertion failed: expected array of children
at Function.error (jquery-1.12.4.min.js:2)
at _assert (jquery.fancytree.js:82)
at jquery.fancytree.js:3242
at i (jquery-1.12.4.min.js:2)
at Object.add [as done] (jquery-1.12.4.min.js:2)
at Fancytree.nodeLoadChildren (jquery.fancytree.js:3229)
at Fancytree._callHook (jquery.fancytree.js:2289)
at FancytreeNode.load (jquery.fancytree.js:1229)
at Fancytree.nodeSetExpanded (jquery.fancytree.js:3965)
at Fancytree.nodeToggleExpanded (jquery.fancytree.js:4230)
You are passing JSON string that defines an object, but the plugin requires an "array of children". Try:
lazyLoad: function (event, data) {
var res = [
{ title: "Sub item", lazy: true },
{ title: "Sub folder", folder: true, lazy: true }
];
data.result = res;
}